SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
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  

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  
 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.01 seconds. Powered By: Snitz Forums 2000