Monday, August 15, 2011

How to populate Time Dimension:

with mycte as
(
select cast('12:00 AM' as time) starttime
union all
select dateadd(s,1,starttime)
from mycte
where dateadd(s,1,starttime) < cast('11:59 PM' as time)
)
select starttime AS Time,datepart(hh,starttime) as Hour,datepart(mi,starttime) as Minutes,datepart(s,starttime) as Seconds
from mycte
OPTION
(MAXRECURSION 0)