In SQL Server as we know, it calculates the week number based on the Jan 1st of the current year till Dec 31st of the current year.
Now what I want is, I want to change these Jan 1st and Dec 31 to Mar 1 and Nov 30. Based on these SQL Server should calculate the week number.
So could anybody give me the SQL script for this?
While you could create very complex expressions using dateadd and datepart, I’d suggest it is much simpler to create a calendar table. It could have a column representing your custom week number that you could calculate exactly one time for your entire range of dates, then it is always available in your queries and much easier to troubleshoot.