Link to home
Start Free TrialLog in
Avatar of apmanzojr1
apmanzojr1Flag for United States of America

asked on

sql statement while loops that displays increment month

Hi everyone,

Can anyone show me on how to create a while loop that shows a increment of months?
Avatar of Cboudroz
Cboudroz

DECLARE @i INT
DECLARE @iNumberOfLoop INT
DECLARE @dtOrderDate DATETIME

SET @iNumberOfLoop = 12
SET @dtOrderDate = GETDATE()

SET @i = 1

WHILE @I >=iNumberOfLoop 
BEGIN


SET @dtOrderDate = DATEADD(m, @i, @dtOrderDate)

PRINT @dtOrderDAte

SET @i = @i+1

END

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America 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
SOLUTION
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