devxlogo

Database Development

Determine Which Version of SQL You Are Running

The following are two T-SQL methods that determine which version of SQL you are running. The first one is very short, using the @@VERSION?variable, whereas the longer method makes use

DateDiff_BIG Function

SQL Server 2016 introduces the DATEDIFF_BIG function that allows you to obtain date differences between larger date ranges. DateDiff_Big returns bigint. Here is a small example: SELECT DATEDIFF_BIG(SECOND, ‘19000101’, ‘20180403’)

Find Duplicates in Your Table

To find duplicates, use a query similar to the following: Select * from TABLE1 a where id ( select max(id) from TABLE1 b where a.Field=b.Field);

A Handy Delete Stored Procedure

Deleting data in a database can a very dangerous operation in the wrong hands. Sometimes you are too busy to really concentrate fully; or sometimes you have given the wrong

Transpose Columns into Rows in SQL

In case you are wondering, yes, there is a different way to transpose columns into rows than making use of a PIVOT structure. However, it is quite a lot of