Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine week by Month and Month Week
Message
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01653958
Message ID:
01653990
Views:
42
>>Hi,
>>
>>I found (online) the following code that determines the month number by Week and Year.
>>
>>declare @Year char(4), @Week tinyint
>>select @Year = '2003', @Week = 10
>>select month(dateadd(wk,@Week,@Year + '/01/01'))
>>
>>
>>How would I use the above expression or is there another expression that will give me the Week Number (in a year, 1-52) if the Month Number (e.g. 1 to 12) is known and the Week Number in the month (1-5)?
>>
>>TIA
>
>I'd definitely recommend creating a date calendar table - basically one row per calendar day, with many columns to describe that day (what week, what fiscal month, what calendar month, etc.) in as many terms as the business needs...

For me this would be additional maintenance. In my application Monday of a Month and how it relates to the Week in a Year is used quite a lot. And these values change from year to year. I prefer to have the program calculate it on-the-fly rather than having to rebuild such a table every year.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform