sql-server-2008-r2

DENSE_RANK according to particular order

百般思念 提交于 2019-12-04 03:19:22
问题 Hi I have a table of data I want to output the dense_rank of the names starting from the first group of names according to sorted dates order. e.g. DROP TABLE MyTable SELECT * INTO MyTable FROM ( VALUES ('2015-12-23', 'ccc'),('2015-12-21', 'aaa'), ('2015-12-20', 'bbb'),('2015-12-22', 'aaa') ) t (date, name) SELECT DENSE_RANK() OVER (ORDER BY name) rank, * FROM MyTable ORDER BY date For the query above I got rank date name 2 2015-12-20 bbb 1 2015-12-21 aaa 1 2015-12-22 aaa 3 2015-12-23 ccc You

get the text of a stored procedure into a variable in SQL Server

梦想与她 提交于 2019-12-04 03:16:05
问题 I want to loop through several stored procs and extract one string form each of them to use in another procedure (basically the 4-part remote server string) So I can get the stored procs list from SysObjects (with Type = P) into a table, then I can loop or cursor through that table variable calling sp_helptext on each one. But how can I get the text result of sp_helptext into a variable so I can do a CharIndex on the word ' BOCTEST ' etc? Is there a table like sys.procedures that stores the

Drop all extended properties on SQL Server

家住魔仙堡 提交于 2019-12-04 02:50:44
How to drop all extended properties on SQL Server in a scriptable way? Co7e If you want a script that will drop all extended properties in one go then use a script that Jamie Thomson has created that will generate drops for all extended properties. You can download it from this article . I've pasted his script here (in full with acknowledgements in-case the article is removed): /* This script will generate calls to sp_dropextendedproperty for every extended property that exists in your database. Actually, a caveat: I don't promise that it will catch each and every extended property that exists

SQL Server 2008 R2: Delete duplicate rows from tables containing in view

烈酒焚心 提交于 2019-12-04 02:31:47
问题 --Creating Table dup1 CREATE TABLE dup1 ( cola VARCHAR(10), colb VARCHAR(10) ); --Insertion of records INSERT INTO dup1 VALUES('1','2'); INSERT INTO dup1 VALUES('1','2'); INSERT INTO dup1 VALUES('1','3'); INSERT INTO dup1 VALUES('1','4'); INSERT INTO dup1 VALUES('1','5'); --Creating Table dup2 CREATE TABLE dup2 ( cola VARCHAR(10), colb VARCHAR(10) ); --Insertion of records INSERT INTO dup2 VALUES('1','2'); INSERT INTO dup2 VALUES('1','2'); INSERT INTO dup2 VALUES('2','3'); INSERT INTO dup2

Convert string into xml and insert Sql Server

丶灬走出姿态 提交于 2019-12-04 02:02:34
We have a SQL Server 2008 R2 database table with XML stored in a column of VARCHAR data type. I now have to fetch some of the elements of the xml. So I want to first convert the xml stored as a VARCHAR data type, to an xml stored as xml data type. Example : Table A Id(int) , ProductXML (varchar(max)) Table B Id(int), ProductXML(XML) I want to convert the ProductXML from Table A into XML data type and insert into Table B . I tried using the CAST() and CONVERT() function as shown below : insert into TableB (ProductXML) select CAST(ProductXML as XML) from TableA; Similarly tried convert but I get

Refresh data from stored procedure

Deadly 提交于 2019-12-04 01:58:03
问题 I have a c# entity framework application. I am trying to run a stored procedure from code (no problem with that). its long running, around 30 mins. I write a log of each transaction to a SQL table as the process goes through. I am looking to initiate the procedure from the app but then show the last 10 records of the log on screen maybe re querying every 10 seconds. this will show the progress. private void Window_Loaded_1(object sender, RoutedEventArgs e) { Task.Run(() => _serviceProduct

Why are the performances of these 2 queries so different?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 01:41:07
I have a stored proc that searches for products (250,000 rows) using a full text index. The stored proc takes a parameter that is the full text search condition. This parameter can be null, so I added a null check and the query suddenly started running orders of magnitude slower. -- This is normally a parameter of my stored proc DECLARE @Filter VARCHAR(100) SET @Filter = 'FORMSOF(INFLECTIONAL, robe)' -- #1 - Runs < 1 sec SELECT TOP 100 ID FROM dbo.Products WHERE CONTAINS(Name, @Filter) -- #2 - Runs in 18 secs SELECT TOP 100 ID FROM dbo.Products WHERE @Filter IS NULL OR CONTAINS(Name, @Filter)

Conversion failed when converting date and/or time from character string in SQL SERVER 2008

一曲冷凌霜 提交于 2019-12-04 01:30:49
问题 I have below SQL. UPDATE student_queues SET Deleted=0, last_accessed_by='raja', last_accessed_on=CONVERT(VARCHAR(24),'23-07-2014 09:37:00',113) WHERE std_id IN ('2144-384-11564') AND reject_details='REJECT' when I ran the above SQL the below exception has been throwed. Conversion failed when converting date and/or time from character string. 回答1: If you're trying to insert in to last_accessed_on , which is a DateTime2 , then your issue is with the fact that you are converting it to a varchar

coordinateSystemId on DbGeography

微笑、不失礼 提交于 2019-12-04 00:52:03
I need to geocode a large number of addresses, using the Bing Map service, EF 5 and SQL Server 2008. I'm using the geography data type in SQL, which translates to a DbGeography type by the EF. When I create a DbGeography object, like this string point = string.Format("POINT({0} {1})",address.Longitude,address.Latitude); address.Location = System.Data.Spatial.DbGeography.PointFromText(point, 4326); The second parameter calls for a "coordinateSystemId". What exactly is this? A lot of the examples I see use 4326. I am new to spatial data, but I'm guessing there is a set of well defined coordinate

IntelliSense is not working in SQL Server Management Studio

狂风中的少年 提交于 2019-12-04 00:19:55
We use SQL Server Management Studio 2008 R2. IntelliSense works with SA account perfectly. But it is not working with Windows Authentication user. The user has access master db with db_owner role but it's not sysadmin. How do I fix this issue? You can try solution from these questions1 or questions2 and questions3 . Or please try these steps as below: Enable IntelliSense: For all query windows, please go to Tools >> Options >> Text Editor >> Transact-SQL >> IntelliSense, and select Enable IntelliSense. For each opening query window, please go to Query >> Intellisense Enabled. Enable statement