SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

gsm113
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.

chadmat
The Chadinator

USA
1974 Posts

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

SET @i = 1

WHILE @i <=3
BEGIN

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

SET @i = @i + 1
END


-Chad
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000