Generate Dates and hour between Date Range
 DECLARE 
  @start DateTime = getdate() -1, 
  @end   DateTime = getdate();
;
WITH Dates_CTE
     AS (SELECT @start AS Dates
         UNION ALL
         SELECT Dateadd(hh, 1, Dates)
         FROM   Dates_CTE
         WHERE  Dates < @end)
SELECT DAY(dates),DATEPART(hour,Dates)
FROM   Dates_CTE
OPTION (MAXRECURSION 0) 
Got better queries? .. Add in comment .. Thanks
No comments:
Post a Comment