Using Microsoft SQL Server, you cannot truncate or drop a table with a foreign key constraint. For example, when you have a client table and a country table. When the client table has a foreign key constraint to the country table, you cannot truncate the country table in this situation …
Read More »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 »T-TSQL – Create 4 week Moving Total
This article will offer you a way to calculate a 4 week moving total in SQL using SQL Server. There are more ways to Rome but this is a way you can use to calculate it using a date dimension.
Read More »Calculate Lost Customers using T-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 »Calculate DateDiff With Only WeekDays or Workdays
Today, I was working on a fact table for my datawarehouse. I was looking for a function to calculate the number of “normal weekdays” between two given dates I had a record in my Dwh from a HR system with two dates (start-end) and a number of hours “sick” . …
Read More »Reset Ident Column in 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 »Script to count nr of rows in all tables
This script can be used as a view to count the number of rows in all SQL tables in your database. This can be very usefull.
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
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 »