Generate Series IN SQL
Generate Series in SQL
DECLARE @startnum INT=1
DECLARE @endnum INT=10;
WITH gen AS (
SELECT DATEADD(DAY,@startnum,'2020-12-30') DT,@startnum AS num
UNION ALL
SELECT DATEADD(DAY,num+1,'2020-12-30') DT,num+1 FROM gen WHERE num+1<=@endnum
)
SELECT num,DT
FROM gen
ORDER BY DT DESC
option (maxrecursion 10000)