T-SQL – Determine the Difference in Values Between Columns in Different Rows

Have you ever needed to calculate the difference between columns in two or more rows in a table using a T-SQL query? For example you might want to run some trend analysis or audit data for changes. Thankfully using ROW_NUMBER() and Common Table Expressions (CTE’s), this can easily be achieved. –create our table DECLARE @TableRows […]

SQL Server Certification – 2 for 1 exam offer

I came across this today and wanted to share it with you. If you are interested in SQL Server certification then for a limited time, Microsoft are offering “2 for 1” on SQL Server exams. Between April 11 2012 and June 30 2012, you can purchase a SQL Server exam at full price and then […]

SQL Server covering index and key lookup performance

In this post, I wanted to write about the covering index and key lookup and how adding covering indexes can help increase performance by reducing lookups to the table data. It’s helpful to know what each of these terms mean and then we will look at an example scenario further down the post. What is […]

GROUPING SETS performance versus UNION performance

GROUPING SETS is a way of aggregating data to produce a result set containing different sets of columns. For the SQL Server platform, it was first introduced in SQL 2008. Prior to SQL Server 2008, achieving this type of result set was possible using UNION, WITH CUBE, WITH ROLLUP and a helper function called GROUPING […]