Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

CTE para obter datas entre duas datas usando o SQL Server


Mudar
select 1 as counter, @maxDate as Date

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

Para torná-lo mais simples, altere o CTE
;with GetDates As  
(  
select DATEADD(day,1,@maxDate) as TheDate
UNION ALL  
select DATEADD(day,1, TheDate) from GetDates  
where TheDate < @curDate  
)
...