Home / Tag Archives: T-SQL

Tag Archives: T-SQL

Calculate Age in SQL Server

In my daily work, I need to calculate and report the age of people very often. There are a couple of ways to calculate the age and will give you the right result. I do not recommend a SQL Function to to this. SQL Functions are performing very slow, especially …

Read More »

Calculate Lost Customers using T-SQL

Calculate Lost Customers in SQL

A common question in the Business Intelligence world from customers is “how many customers did we lose this year” ? Businesses wants to know this so they can act faster to keep customers doing business with them. In this article, I will help you to create SQL to calculate this …

Read More »

How To Find the slowest SQL Queries


This stored procedure displays the top worst performing queries based on CPU, Execution Count, I/O and Elapsed_Time as identified using DMV information.  This can be display the worst performing queries from an instance, or database perspective.   The number of records shown, the database, and the sort order are identified by …

Read More »

Reset Ident Column in Database

Reset Ident Field in a Database

This is a very handy little script to generate a script to reset the ident column of all your database tables. This can be handy after filling and truncating tables. This script uses a schema “ps”. Replace it with .dbo if needed.

Read More »

Calculate Weeks Between Two Dates using DateDiff

In SQL Server, there’s a buildin function to calculate the number of weeks between two dates. This function is called “DateDiff”. The problem with this function is that Sql Server thinks the week starts on sunday. Maybe this it true in some situations but at  my current project,  the week …

Read More »

Running Totals / Cumulatieven berekenen

Cumulatieven berekenen SQL Server

Op internet is er al veel over geschreven maar ik vond het de moeite waard om een artikel te posten over Running Totals / Cumulatieven berekenen binnen Microsoft SQL Server 2005 / 2008. Er zijn diverse manieren om dit te doen. De meest snelle manier wordt in dit artikel besproken.

Read More »

T-SQL Group By ALL

Zodra je een T-SQL Query typt wil je de data vaak groeperen. Vandaag kwam ik achter een grappig truukje bij het groeperen, de GROUP BY ALL mogelijkheid. Wellicht wat lastig uit te leggen wat het precies doet maar met een paar voorbeelden erbij zou het moeten lukken!

Read More »