sql >> Base de Datos >  >> RDS >> Sqlserver

CTE para obtener fechas entre dos fechas usando SQL Server

Cambiar

select 1 as counter, @maxDate as Date

a

select 1 as counter, DATEADD(day,1,@maxDate) as Date

Para hacerlo más simple, cambie el CTE

;with GetDates As  
(  
select DATEADD(day,1,@maxDate) as TheDate
UNION ALL  
select DATEADD(day,1, TheDate) from GetDates  
where TheDate < @curDate  
)
...