Posts

How to compare two tables for differences?

How to compare two tables for differences? Execute the following Microsoft SQL Server 2008 T-SQL scripts in Query Editor to demonstrate the comparison of two tables for differences in rows and/or columns (cells). ------------ -- SQL SERVER COMPARE 2 TABLES FOR ROW & COLUMN DIFFERENCES ------------ -- TEMPLATE - SQL Server T-SQL compare two tables SELECT Label = 'Found IN Table1, NOT IN Table2' ,* FROM ( SELECT * FROM Table1   EXCEPT   SELECT   * FROM Table2 ) x UNION ALL SELECT Label = 'Found IN Table2, NOT IN Table1' ,* FROM ( SELECT   * FROM Table2   EXCEPT   SELECT * FROM Table1 ) y GO ------------ -- SQL Server T-SQL compare Product tables for 2005 & 2008 SELECT Label = 'Found IN AW

How to convert from string to datetime?

How to convert from string to datetime? Execute the following T-SQL scripts in Microsoft SQL Server Management Studio (SSMS) Query Editor to demonstrate T-SQL CONVERT and CAST functions in transforming string SQL date formats, string time & string datetime data to datetime data type. Practical examples for T-SQL DATE / DATETIME functions. -- SQL Server string to date / datetime conversion - datetime string format sql server -- MSSQL string to datetime conversion - convert char to date - convert varchar to date -- Subtract 100 from style number (format) for yy instead yyyy (or ccyy with century ) SELECT convert ( datetime , 'Oct 23 2012 11:01AM' , 100 ) -- mon dd yyyy hh:mmAM (or PM) SELECT convert ( datetime , 'Oct 23 2012 11:01AM' ) -- 2012-10-23 11:01:00.000