DECLARE @FirstDateOfYear DATETIME
SET @FirstDateOfYear = ‘2010-01-01′
SELECT DISTINCT DATEADD(d, number, @FirstDateOfYear),
CASE DATEPART(dw, DATEADD(d, number, @FirstDateOfYear))
WHEN 7 THEN ‘Saturday’
WHEN 1 THEN ‘Sunday’
ELSE ‘Work Day’
END
FROM master..spt_values
WHERE number BETWEEN 0 AND 364
AND (DATEPART(dw, DATEADD(d, number, @FirstDateOfYear)) = 1 OR DATEPART(dw, DATEADD(d, number, @FirstDateOfYear)) = 7)
ORDER BY DATEADD(d, number, @FirstDateOfYear)
This is the script I replied the article Get Date of All Weekdays or Weekends of the Year on SQLAuthority.com
Tuesday, December 29, 2009
Get all weekends in year 2010
at 5:22 AM
Labels: SQL Server, SQL Server Tip
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment