I have a date column in a table and I want to get week number for that particular date based on the month from that date irrespective of the day
For example:
01-dec-2012 to 07-dec-2012 should give week number as 1
08-dec-2012 to 14-dec-2012 should give week number as 2
15-dec-2012 to 21-dec-2012 should give week number as 3
22-dec-2012 to 28-dec-2012 should give week number as 4
29-dec-2012 to 31-dec-2012 should give week number as 5
This week number is not dependent on the starting day of the week i.e, it can be any day
How can I write a select statement to get this output in SQL Server 2008?
You can use DAY (Transact-SQL)
SQL Fiddle
MS SQL Server 2012 Schema Setup:
Query 1:
Results: