SQL query statistics

This is no work of mine but I wanted to highlight it since it´s such a good thing to utilise when optimizing your database and queries. SELECT SUBSTRING(qt.text, (qs.statement_start_offset/2)+1, ((CASE qs.statement_end_offset WHEN -1 THEN DATALENGTH(qt.text) ELSE...

Rounding or grouping datetime in SQL

When retrieving data for statistical usage in SQL it´s often useful to group the data to some kind of time interval. Easiest and most used is probably simple grouping by date: SELECT cast(Timestamp as date), COUNT(*) FROM MyTable GROUP BY cast(Timestamp as date)...

Want to group by date? Cast to date!

When extracting timed statistics from SQL you usually want these stats grouped by some kind of time and more often than not this time unit is days. I used to do this unnecessarily complicated by converting the dates to varchars in formats I didn’t even want and...

SQL Bottlenecks

In our environment we´ve got a heavily loaded SQL Server as a trunk in the system. Most systems look like this and sooner or later you will probably want to troubleshoot bottlenecks in this database. From a nice fellow at Microsoft we got handed the scripts from Jimmy...