Thursday, March 27, 2014

Unpivot table between two dates

Try



WITH dates AS
(SELECT 'Kadir' Name,'(Holiday)' as subject, {d N'2013-07-12'} AS [Date],{d N'2013-07-24'} as [date2]
UNION ALL
SELECT 'Kadir' Name,'(Holiday)' as subject, DATEADD(day, 1, [Date]) AS [Date],{d N'2013-07-24'} as [date2]
FROM dates
WHERE [Date] < {d N'2013-07-24'})
-- INSERT INTO myTable (DateColum)
SELECT name,subject,[Date],[Date2]
FROM dates
OPTION (MAXRECURSION 13);





Many Thanks & Best Regards, Hua Min


No comments:

Post a Comment