Generate Weekdays in SQL Server

In this post, I am sharing simple script to generate weekdays in SQL server.

select  [DayId] = number
      , [DayName] = datename(dw, convert(datetime, cast(19000100 + number as varchar)))
from master.dbo.spt_values
where type = 'P' and number between 1 and 7
Result

Refer related posts

Generate Weekdays in SQL Server Generate Weekdays in SQL Server Reviewed by Sandeep Mittal on Friday, December 28, 2012 Rating: 5

No comments:

Powered by Blogger.