Solved

sql statement while loops that displays increment month

Posted on 2012-04-05
3
722 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now