I will give stars to the person(s) who can come up with a better/faster/easier solution to get the next thanksgiving days by using SQL
Here is my code
CREATE TABLE #NumberPivot (Number INT PRIMARY KEY)
DECLARE @intLoopCounter INT
SELECT @intLoopCounter =0
WHILE @intLoopCounter <(10 *365)
BEGIN
INSERT INTO #NumberPivot
VALUES (@intLoopCounter)
SELECT @intLoopCounter = @intLoopCounter +1
END
SET DATEFIRST 7
DECLARE @dtmStardate DATETIME
SELECT @dtmStardate ='2005-11-24 00:00:00.000'
SELECT MAX((DATEADD(d,number,@dtmStardate))) AS ThanksGivingDay,
DATEPART(yyyy,DATEADD(d,number,@dtmStardate)) AS [Year]
FROM dbo.#NumberPivot
WHERE DATEPART(dw,DATEADD(d,number,@dtmStardate)) = 5
AND DATEPART(mm,DATEADD(d,number,@dtmStardate)) = 11
GROUP BY DATEPART(mm,DATEADD(d,number,@dtmStardate)) ,DATEPART(yyyy,DATEADD(d,number,@dtmStardate))
ORDER BY 1
--By the way Happy Thanksgiving
Denis The SQL Menace
SQL blog:
Personal Blog:
Here is my code
CREATE TABLE #NumberPivot (Number INT PRIMARY KEY)
DECLARE @intLoopCounter INT
SELECT @intLoopCounter =0
WHILE @intLoopCounter <(10 *365)
BEGIN
INSERT INTO #NumberPivot
VALUES (@intLoopCounter)
SELECT @intLoopCounter = @intLoopCounter +1
END
SET DATEFIRST 7
DECLARE @dtmStardate DATETIME
SELECT @dtmStardate ='2005-11-24 00:00:00.000'
SELECT MAX((DATEADD(d,number,@dtmStardate))) AS ThanksGivingDay,
DATEPART(yyyy,DATEADD(d,number,@dtmStardate)) AS [Year]
FROM dbo.#NumberPivot
WHERE DATEPART(dw,DATEADD(d,number,@dtmStardate)) = 5
AND DATEPART(mm,DATEADD(d,number,@dtmStardate)) = 11
GROUP BY DATEPART(mm,DATEADD(d,number,@dtmStardate)) ,DATEPART(yyyy,DATEADD(d,number,@dtmStardate))
ORDER BY 1
--By the way Happy Thanksgiving
Denis The SQL Menace
SQL blog:
Personal Blog: