Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Ottieni tutte le date del mese e dell'anno indicati in SQL Server

Stesso approccio di t-clausen, ma più compatto:

Declare @year int = 2017, @month int = 11;
WITH numbers
as
(
    Select 1 as value
    UNion ALL
    Select value + 1 from numbers
    where value + 1 <= Day(EOMONTH(datefromparts(@year,@month,1)))
)
SELECT datefromparts(@year,@month,numbers.value) Datum FROM numbers