Solved

sql statement while loops that displays increment month

Posted on 2012-04-05
3
736 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

740 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