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)
 how to count variables in proc

Author  Topic 

Bhavan
Starting Member

8 Posts

Posted - 2008-02-21 : 16:13:52
guys, is there way we can write a stored proc that would take minmum of 50 input IDs (numbers) and check those IDs exist or not in a table in the db. i know what to do if exist, however I am little stumbled on accpting 50 numbers as cmdline variables to the stored proc.

Appareciate your help with this. Note that, I don't want to declare 50 local variables as @i1, @i2...@i50.

Thanks

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-02-21 : 17:36:37
you can pass them in CSV form and split them in the sproc.
search for split CSV on this site and you'll get plenty of hits.

another way is to pass them as xml and use built-in xml capabilities like nodes()
function to transfrom the xml into a table

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-22 : 01:19:31
http://www.sommarskog.se/arrays-in-sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Bhavan
Starting Member

8 Posts

Posted - 2008-02-22 : 16:46:20
Thanks for your valuable thoughts Spirit1 & Madhivanan. Truly appreciated !.
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-02-23 : 12:41:14
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page
   

- Advertisement -