How to Pivot Data in SQL Server

Sometimes it just makes sense to output a pivoted table, instead of purely columnar data, when running a T-SQL select query. It's easy to think of pivoting as a complex process when being implemented in code (as opposed to the visual environment of Excel for example), however it's actually quite…

Finding The Start of a Week in SQL Server

I came across a little gem the other week and use it all the time when I need to measure results over a period of weeks - this identifies the start of the current week so can be easily used in a variable, for example, as an 'end date' parameter in my query. It goes like this:-…