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)
 receiving N number of parameters to a Procedure

Author  Topic 

shebert
Yak Posting Veteran

85 Posts

Posted - 2010-02-25 : 10:25:19
So I have a programmer that wants me to build a procedure to accept data that is inconsistent.


depending what happens on a test station he would like to run a procedure against sql like this: sp_add_pacakge '12,15,35', 'yes,no,yes', 'blue,red,green'


then have the procedure populate table called like test_result

with three columns

ID,PASS,COLOR

12 yes blue
15 no red
35 yes green


Please help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-25 : 10:32:10
not a good approach. better to pass a single string value like below

sp_add_pacakge '12,yes,blue;15,no,red;35,yes,green'


and then insert them to various rows of table

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

shebert
Yak Posting Veteran

85 Posts

Posted - 2010-02-25 : 10:55:40
OK But when data is passes like this how do you handle it with sql code?

12,no,blue;13,yes,red

Steve
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-25 : 11:03:41
quote:
Originally posted by shebert

OK But when data is passes like this how do you handle it with sql code?

12,no,blue;13,yes,red

Steve


use a udf which parses this text and get individual values.

See a similar udf here

http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

shebert
Yak Posting Veteran

85 Posts

Posted - 2010-02-25 : 11:31:09
Thanks A BUNCH
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-25 : 11:31:44
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -