Solved

sql statement while loops that displays increment month

Posted on 2012-04-05
3
733 Views
Last Modified: 2012-04-13
Hi everyone,

Can anyone show me on how to create a while loop that shows a increment of months?
0
Comment
Question by:apmanzojr1
3 Comments
 
LVL 7

Expert Comment

by:Cboudroz
ID: 37814577
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

0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 400 total points
ID: 37814605
Can anyone show me on how to create a while loop
Why does it have to be a while loop?

that shows a increment of months?
Can you tell us what output to expect?
0
 
LVL 25

Assisted Solution

by:jogos
jogos earned 100 total points
ID: 37815303
@Cboudroz
If you increment in the loop, please take other result-variable for the output
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question