|
Post by Admin on Sept 8, 2015 11:58:38 GMT
Hi, today I found a nice SQL for generate all date range data in row with a CTE expression.
DECLARE @start DATE, @end DATE; SELECT @start = '20150901', @end = '20151001';
;WITH n AS ( SELECT TOP (DATEDIFF(DAY, @start, @end) + 1) n = ROW_NUMBER() OVER (ORDER BY [object_id]) FROM sys.all_objects ) SELECT DATENAME(dw, DATEADD(DAY, n-1, @start)), DATEADD(DAY, n-1, @start) AS ReportDate FROM n;
Enjoy!!!
|
|