Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine week by Month and Month Week
Message
From
05/09/2017 02:40:25
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01653958
Message ID:
01654010
Views:
52
>>>This logic has been in the business of the application for a long time and works well. Each month has from 4 to 5 weeks, or better said, has 4 to 5 Mondays. Therefore, in this logic given that the Monday Number (1 to 5 ) is known and the month, the program needs to know the week number in a year. Example
>>>Month: September
>>>Week: 1 (which is the week of September 4th, 2017)
>>>And I need to find the week number in a year. I know it is a week 36 this year. But I need to find the way to determine this in T-SQL language. So that the setting can be done in one SQL Server update/insert statement.
>>>
>>>If this is not possible, I will have to do it from VFP PRG code, which is not that difficult.
>>>
>>>>I get the feeling that you are painting yourself into a corner using somewhat arbitrary definitions like month week ;-)
>>>>Meditate on the biz need for month week and probably save the date in the DB.
>>>>If you need fast grouping, index to special tags via formula from saved date.
>>>>Or perhaps create virtual fields from the date...
>>>>
>>>>>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
>>
>>Will this do it: https://stackoverflow.com/questions/42794544/get-week-number-in-year-from-date ?
>>Note the last answer which includes 'set datefirst'
>
>This may provide the answer to my question if I figure how to get the Date from the number of a Monday in a month. Like, what is the date of the 2nd Monday of September 2017.
>Thank you.

I'm not a SQL man but isn't that what 'set datefirst' does?

https://docs.microsoft.com/en-us/sql/t-sql/statements/set-datefirst-transact-sql
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform