Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL looping with changing variable
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 11/08/2012 :  19:01:38  Show Profile  Reply with Quote
Hi all,

I would like to run a set of SQL code on a repeat loop, with each loop using a different value for a specific parameter.

In other words, I have a data set (X,Y,Z) and I want to run the code passing X as a variable, using Y, and then again using Z.

If anyone can get me started down the right path I would greatly appreciate it.

The Chadinator

1974 Posts

Posted - 11/09/2012 :  02:58:56  Show Profile  Visit chadmat's Homepage  Reply with Quote

SET @i = 1

WHILE @i <=3

IF @i = 1 EXEC myProc 'X'
ELSE IF @i = 2 EXEC myproc 'Y'
ELSE IF @i = 3 EXEC myProc 'Z'

SET @i = @i + 1

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000