After experimentation with various datepart and datename methods following my most recent blog post, I was able to identify many if not all the necessary components for constructing a calendar table.To do this I have combined these functions with the SQL to generate a list of dates as posted by Jamie some time ago. The resultant SQL is given below, and hopefully does not require any specific explanation, however feel free to leave me a comment if you would like clarification on any part of it.
with mycte as
(
select cast('2007-04-16' as datetime) DateValue
union all
select DateValue + 1
from mycte
where DateValue + 1 < '2007-04-23'
)
select DateValue
, datepart(dy, DateValue) [day of year]
, datename(dw, DateValue) [day]
, datepart(dw, DateValue-1) [day of week]
, datepart(dd, DateValue) [day of month]
, datepart(ww, DateValue) [week]
, datepart(mm, DateValue) [month]
, datename(mm, DateValue) [month]
, datepart(qq, DateValue) [quarter]
, datepart(yy, DateValue) [year]
, datepart(HH, DateValue) [HOUR]
, datepart(MI, DateValue) [MIN]
, datepart(SS, DateValue) [SEC]
, datepart(MS, DateValue) [MILLISECOND]
from mycte
OPTION (MAXRECURSION 0)
James