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