Tag

#T-SQL

11 blogs

  1. Cannot truncate table because it is being referenced by a FOREIGN KEY constraint

    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 ...

    SQL Server7 Sep 2017 · 16.4k reads
    16.4k
  2. 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 ...

    SQL Server3 comments2 Feb 2016 · 11.7k reads
    11.7k
  3. 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.

    SQL Server, Power BI7 Dec 2015 · 7.4k reads
    7.4k
  4. 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 ...

    SQL Server20 Aug 2014 · 5.7k reads
    5.7k
  5. 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 ...

    SQL Server3 Mar 2014 · 4.4k reads
    4.4k
  6. 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 ...

    SQL Server6 Jun 2012 · 12.5k reads
    12.5k
  7. 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". ...

    SQL Server14 May 2012 · 4k reads
    4k
  8. 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.

    SQL Server14 May 2012 · 4.2k reads
    4.2k
  9. 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 ...

    SQL Server1 comment30 Mar 2012 · 50.2k reads
    50.2k
  10. Calculating running totals

    A lot has been written about it on the internet already, but I thought it was worth posting an article about calculating running totals in Microsoft SQL Server 2005 / 2008. There are ...

    SQL Server24 May 2011 · 5.3k reads
    5.3k
  11. T-SQL Group By ALL

    When you type a T-SQL Query, you often want to group the data. Today I came across a neat trick for grouping: the GROUP BY ALL option. It may be a bit hard to explain what it ...

    SQL Server26 Feb 2009 · 3.7k reads
    3.7k
(11 rows affected)sqlblog.nl