0

This question is for SQL Server 2008 (T-SQL). I'd like to get quick reply to this question please.

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
  • 1
    Welcome to Stack Overflow! There's no need to ask for a quick reply or include a complete signature. We can see who posted the question, and asking for a quick reply won't make it any quicker. – Jamie - Fenrir Digital Ltd Feb 14 '18 at 18:28

1 Answers1

0

I think your question is already answered in stackoverflow.

Take a look at this:

How to get week number of the month from the date in sql server 2008

Is what are you looking for?

Gyntonic
  • 346
  • 2
  • 4
  • 14
  • Thank you, Close but not on the nail :) I would like to get a table using that SQL stmt something like this: Week of 1/1 Referrals Per Hour Week of 1/8 Referrals Per Hour Week of 1/15 Referrals Per Hour Week of 1/22 Referrals Per Hour Week of 1/29 Referrals Per Hour "Business Hours" 32 40 32 40 24 – Orhan Erten Feb 14 '18 at 18:57
  • Thank you, Close but not on the nail :) I would like to get a table using that SQL stmt something like this: Week of 1/1 Referrals Per Hour Week of 1/8 Referrals Per Hour Week of 1/15 Referrals Per Hour Week of 1/22 Referrals Per Hour Week of 1/29 Referrals Per Hour "Business Hours" 32 40 32 40 24 I wouuld like to attach this as an image but don't know how to do this in STackflow blog. So there will be for instance for January five columns because the month has five weeks. – Orhan Erten Feb 14 '18 at 19:06
  • Bryan Focht: Just look at the date and see what range it falls in. Range 1-7 is the 1st week, Range 8-14 is the 2nd week, etc. SELECT CASE WHEN DATEPART(day,yourdate) < 8 THEN '1' ELSE CASE WHEN DATEPART(day,yourdate) < 15 then '2' ELSE CASE WHEN DATEPART(day,yourdate) < 22 then '3' ELSE CASE WHEN DATEPART(day,yourdate) < 29 then '4' ELSE '5' END END END END – Orhan Erten Feb 14 '18 at 19:46
  • Sorry, I think I'm not understanding you. The code you have written should do what you are asking. Does it works? – Gyntonic Feb 15 '18 at 18:20
  • That code I got from Bryan's blog entry works but I needed first Monday of the week in month in any year. Then I can calculate hopefully each business week (M-F) from that day on. I found following SQL stmt. and tested it and works: SELECT DATEADD(WEEK, DATEDIFF(WEEK, 0, GETDATE()), 0) as 'Monday of Current Week' UNION ALL SELECT DATEADD(WEEK, DATEDIFF(WEEK, 0, DATEADD(DAY, 6 - DATEPART(DAY, GETDATE()), GETDATE())), 0) as 'First Monday of Current Month' Review me – Orhan Erten Feb 16 '18 at 18:06