April 10, 2013 at 5:27 am
I'll take the advice of you folks and go with the calendar.
Thanx.
April 10, 2013 at 6:05 am
FollowingSaturday = DATEADD(day,6-DATEDIFF(day,6,Today)%7,Today)
-- example
;WITH ATableOfDates AS (
SELECT TOP(300)
Today = DATEADD(DAY,ROW_NUMBER() OVER(ORDER BY (SELECT NULL))-150,CAST(GETDATE() AS DATE))
FROM sys.columns
)
SELECT
Today,
[DayOfWeek] = DATENAME(weekday,Today),
FollowingSaturday = DATEADD(day,6-DATEDIFF(day,6,Today)%7,Today)
FROM ATableOfDates
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
April 10, 2013 at 6:08 am
Thanx.
March 4, 2015 at 9:56 am
Excellent! Adding the difference in weeks to the first supported Saturday (day 5) does the trick.
Thanks!
Viewing 4 posts - 16 through 18 (of 18 total)
You must be logged in to reply to this topic. Login to reply