Smart way to expand dates for a month in SQL serve query

with D as (
select distinct CreationTime MDATE from [jwtest].[System.Activities.DurableInstancing].[InstancesTable]
where CreationTime>=’2023-02-01′ and CreationTime<‘2024-02-01’
UNION ALL
SELECT dateadd(d, 1, MDATE) MDATE
FROM D where datediff(m, MDATE, dateadd(d, 1,MDATE))=0)
select MDATE from D

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment