Loop Through Dates in SQL
DECLARE @StartDate DATE = '2019-12-17';
DECLARE @EndDate DATE = '2021-05-01'
declare @Edate date
declare @sdate date
set @Edate = DATEADD(day, 30, @StartDate)
set @sdate = @StartDate
WHILE (@Edate <= @EndDate)
BEGIN
print 'start'
print @sdate
print @Edate
set @sdate = @Edate
set @Edate = DATEADD(day, 30, @sdate);
print @sdate
print @Edate
print 'end'
END
Comments
Post a Comment