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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 @ID = from 2 to 200?

Author  Topic 

xoail
Starting Member

9 Posts

Posted - 2008-05-16 : 17:55:50
While exicuting a stored procedure, I want to provide the following parameters on which one needs to have values 2 to 200 and the procedure must run for each value at a time. Its something like this

exec procedurename @para1 =123, @para2=3432, @para3 = from 2 to 200

Obviously Im getting a syntax error. How can I write the values for para3?
Appreciate your help!

Thanks.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-05-16 : 18:25:20
I'm suspicious of the need to "run for each value at a time"...but anyway

you could split them into 2 ie: @para3From and @para3To (that is what I'd do)
you could encode a value using a string or binary ie: binary(8) 0x00000002000000C8 (two 4 bytes together)
or '2-200' then split the value using string functions.

Be One with the Optimizer
TG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-17 : 02:51:12
quote:
Originally posted by xoail

While exicuting a stored procedure, I want to provide the following parameters on which one needs to have values 2 to 200 and the procedure must run for each value at a time. Its something like this

exec procedurename @para1 =123, @para2=3432, @para3 = from 2 to 200

Obviously Im getting a syntax error. How can I write the values for para3?
Appreciate your help!

Thanks.


What is the procedure doing and why are you calling it for range of values?
Go to Top of Page

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2008-05-17 : 05:38:22
try it in While loop..
Declare @i int
set @i=2
While @i<=200
Begin
exec procedurename 123, 3432, @i
End


Go to Top of Page

bjoerns
Posting Yak Master

154 Posts

Posted - 2008-05-19 : 05:51:58
Hey and insert an 'set @i = @i + 1' after the exec. Takes too long otherwise.
Go to Top of Page

xoail
Starting Member

9 Posts

Posted - 2008-05-19 : 09:19:59
Its taking a long time using the while loop. Any other way?
Thanks!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-19 : 09:21:27
Yes.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-19 : 09:22:37
See http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -