385
votes
17answers
562k views

How to SELECT * INTO [temp table] FROM [stored procedure]

How do I do a SELECT * INTO [temp table] FROM [stored procedure]? Not FROM [Table] and without defining [temp table]? Select all data from BusinessLine into tmpBusLine works fine. select * into ...
101
votes
10answers
76k views

What represents a double in sql server?

I have a couple of properties in C# which are double and I want to store these in a table in SQL Server, but noticed there is no double type, so what is best to use, decimal or float? This will store ...
69
votes
7answers
118k views

SQL update query using joins

I have to update a field with a value which is returned by a join of 3 tables. Example: select im.itemid ,im.sku as iSku ,gm.SKU as GSKU ,mm.ManufacturerId as ManuId ...
53
votes
4answers
20k views

Dynamic SELECT TOP @var In SQL Server

How can I have a dynamic variable setting the amount of rows to return in SQL Server? Below is not valid syntax in SQL Server 2005+: DECLARE @count int SET @count = 20 SELECT TOP @count * FROM ...
38
votes
8answers
20k views

SQL Server - where is “sys.functions”?

SQL Server 2005 has great sys.XXX views on the system catalog which I use frequently. What stumbles me is this: why is there a "sys.procedures" view to see info about your stored procedures, but ...
37
votes
8answers
70k views

SQL Server - SELECT FROM stored procedure

I have a stored procedure that returns rows: CREATE PROCEDURE MyProc AS BEGIN SELECT * FROM MyTable END My actual procedure is a little more complicated, which is why a sproc is necessary. Is ...
28
votes
6answers
22k views

Get top 1 row of each group

I have a table which I want to get the latest entry for each group. Here's the table: DocumentStatusLogs Table |ID| DocumentID | Status | DateCreated | | 2| 1 | S1 | 7/29/2011 | | 3| ...
27
votes
6answers
16k views

WITH (NOLOCK) vs SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

Could someone give me some guidance on when I should use WITH (NOLOCK) as opposed to SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED What are the pros/cons of each? Are there any unintended ...
19
votes
4answers
29k views

How do I escape a single quote in sqlserver?

I'm trying to insert some text data into a table in SQLServer 9. The text includes a single quote. How do I escape that? I tried using two single quotes, but it threw me some errors. eg. insert into ...
17
votes
4answers
13k views

Better techniques for trimming leading zeros in SQL Server?

I've been using this for some time: SUBSTRING(str_col, PATINDEX('%[^0]%', str_col), LEN(str_col)) However recently, I've found a problem with columns with all "0" characters like '00000000' because ...
12
votes
6answers
5k views

What is the best way to delete a large number of records in t-sql?

We've run across a slightly odd situation. Basically there are two tables in one of our databases that are fed tons and tons of logging info we don't need or care about. Partially because of this ...
8
votes
1answer
67k views

Convert a string to int using sql query

How to convert a string to integer using SQL query on SQL Server 2005?
8
votes
4answers
12k views

Find Non-Ascii Characters in One Varchar Column or Mulitiple Columns using SQL Server

How can rows with Non-Ascii Characters be returned using SQL Server? If you can show how to do it for one column would be great. I am doing something like this now but it is not working select * ...
7
votes
5answers
10k views

How to change column order in a table using sql query in sql server 2005?

How to change column order in a table using sql query in sql server 2005? I want to rearrange column order in a table using sql query. Please help.
5
votes
6answers
2k views

How to print VARCHAR(MAX) using Print Statement?

I have a code which is: DECLARE @Script VARCHAR(MAX) SELECT @Script = definition FROM manged.sys.all_sql_modules sq where sq.object_id = (SELECT object_id from managed.sys.objects Where type = 'P' ...

1 2 3 4 5 427
15 30 50 per page