Solved

sql statement while loops that displays increment month

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
t-sql Joining Issue 10 40
query execution hang 5 29
SQL server vNext 18 29
SQL Function NOT ROUND 9 10
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

778 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