SQL First Day of Month

2020-03-07T17:05:33+00:00May 19th, 2011|SQL|

This post describes how to find the first day of a month in SQL. The code is: DATEADD(mm,DATEDIFF(mm,0,DateToRemoveTime),0) A full explanation of how this works is in a previous post describing how to remove the time portion of a datetime in SQL. This is exactly the same except use the month (mm) instead of day.

SQL Calculating the row number

2020-03-07T10:21:09+00:00May 7th, 2011|SQL|

To label the row number in SQL there's a useful little in built SQL function you need to use, row_number() This enables you to number all rows and also restart the row numbering to partition your data. Note this is different to the SQL rank function. This is a very useful thing is you want [...]

Remove the time from a datetime in SQL

2020-03-19T14:39:36+00:00April 27th, 2011|SQL|

There are a few ways to remove the time from a datetime in SQL. This article describes a couple of them. This is the code: DATEADD(dd,0,DATEDIFF(dd,0,DateToRemoveTime)) I'll explain how this works as it was quite confusing initially. Part 1: DATEDIFF(dd,0,DateToRemoveTime) What this is doing is finding the number of whole days (without time) from the [...]