
sql - NOT IN vs NOT EXISTS - Stack Overflow
Which of these queries is the faster? NOT EXISTS: SELECT ProductID, ProductName FROM Northwind..Products p WHERE NOT EXISTS ( SELECT 1 FROM Northwind..[Order Details] od …
SQL: IF clause within WHERE clause - Stack Overflow
Sep 18, 2008 · Is it possible to use an IF clause within a WHERE clause in MS SQL? Example: WHERE IF IsNumeric(@OrderNumber) = 1 OrderNumber = @OrderNumber ELSE OrderNumber LIKE '%' + @
sql - Concatenate text from multiple rows into a single text string ...
Consider a database table holding names, with three rows: Peter Paul Mary Is there an easy way to turn this into a single string of Peter, Paul, Mary?
sql - Copy data into another table - Stack Overflow
How to copy/append data from one table into another table with same schema in SQL Server? Edit: let's say there is a query select * into table1 from table2 where 1=1 which creates table1 wi...
SQL to find the number of distinct values in a column
I can select all the distinct values in a column in the following ways: SELECT DISTINCT column_name FROM table_name; SELECT column_name FROM table_name GROUP BY column_name; But how …
sql server - SQL MAX of multiple columns? - Stack Overflow
Mar 8, 2012 · How do you return 1 value per row of the max of several columns: TableName [Number, Date1, Date2, Date3, Cost] I need to return something like this: [Number, Most_Recent_Date, Cost] …
sql - Selecting COUNT (*) with DISTINCT - Stack Overflow
In SQL Server 2005 I have a table cm_production that lists all the code that's been put into production. The table has a ticket_number, program_type, program_name and push_number along with some ot...
How to set variable from a SQL query? - Stack Overflow
I'm trying to set a variable from a SQL query: declare @ModelID uniqueidentifer Select @ModelID = select modelid from models where areaid = 'South Coast' Obviously I'm not doing this right as it ...
sorting - SQL multiple column ordering - Stack Overflow
Jan 12, 2010 · How can I sort multiple columns in SQL and in different directions? For instance, 'column1' would be sorted descendingly and 'column2' ascendingly.
How to convert a datetime to string in T-SQL - Stack Overflow
In addition to the CAST and CONVERT functions in the previous answers, if you are using SQL Server 2012 and above you use the FORMAT function to convert a DATETIME based type to a string.