Link to home
Start Free TrialLog in
Avatar of rick
rick

asked on

Loop to go backward 90 days

Trying to get a rolling 90 day for loop to work.  First line should be yesterday's date, next line would be day before yesterday's date...until reach 90 days prior.  But when I run the following it skips days and doesn't give desired results.

DECLARE @cnt INT = 0;
DECLARE @DATE DATE = GETDATE() 

WHILE @cnt < 90
BEGIN
	
   PRINT @DATE 

   SET @DATE = DATEADD(D, @cnt*-1, @DATE);
   SET @cnt = @cnt + 1
END;

Open in new window

Capture.PNG
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rick
rick

ASKER

perfect!  thanks