Category Archives: SQL 2008 R2

Using INSERT to Remove Duplicate Rows (IGNORE_DUP_KEY)

Create a duplicate structure of the table concerned and build an IGNORE_DUP_KEY index over the second table that includes all the original table candidate keys and insert rows into it. forename surname age ————— ————— ———– David Selwood 40 Paul … Continue reading

Posted in SQL 2005, SQL 2008, SQL 2008 R2 | Tagged | Comments Off on Using INSERT to Remove Duplicate Rows (IGNORE_DUP_KEY)

Rounding a Date (removing time)

Posted in SQL 2005, SQL 2008, SQL 2008 R2 | Tagged | Comments Off on Rounding a Date (removing time)

Cast or Convert

Syntax for CAST: CAST ( expression AS data_type [ (length ) ]) Syntax for CONVERT: CONVERT ( data_type [ ( length ) ] , expression [ , style ] ) CONVERT is specific to SQL Server, and allows for a … Continue reading

Posted in SQL 2005, SQL 2008, SQL 2008 R2 | Tagged | Comments Off on Cast or Convert

Forcing the Screen Buffer to be Displayed

In order to force the contents of the screen buffer to be outputted staight away please use the following SQL:

Posted in SQL 2005, SQL 2008, SQL 2008 R2 | Tagged | Comments Off on Forcing the Screen Buffer to be Displayed

Performing a Case Sensitive Comparison when SQL Server is Configured as Case-Insensitive

A case sensitive check can be performed by casting both columns or constants to the VARBINARY type; see examples below:

Posted in SQL 2005, SQL 2008, SQL 2008 R2 | Tagged | Comments Off on Performing a Case Sensitive Comparison when SQL Server is Configured as Case-Insensitive

Checking If A Local Temporary Table Already Exists

To test if a temporary table already exists, the “OBJECT_ID” system function can be used. For example the following code tests to see if the local temporary table ‘#AnyTable’ already exists and if the table exists the word ‘EXISTS’ is … Continue reading

Posted in SQL 2005, SQL 2008, SQL 2008 R2 | Tagged | Comments Off on Checking If A Local Temporary Table Already Exists

Microsoft SQL Server Versions

Execute the following SQL query: .

Posted in SQL 2005, SQL 2008, SQL 2008 R2 | Tagged | Comments Off on Microsoft SQL Server Versions