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 2000 Forums
 SQL Server Development (2000)
 are variable input parameter lists possible??

Author  Topic 

gdeconto
Posting Yak Master

107 Posts

Posted - 2002-03-06 : 19:33:46
I was looking at writing a stored procedure that would be referenced from a variety of locations.

The problem is that the number of input parameters being passed to the stored procedure is not known ahead of time.

ie. the first time the sproc is called, it may have one parameter, the second time it could have twenty parameters.

I would use this list of parameters to build a dynamic sql stmt to execute.

Any recommendations, aside from giving up??

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-03-06 : 19:55:36
You might be able to pass multiple values as a CSV and split them out. Check this link:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=13459

And check the articles on SQL Team under "CSV":

http://www.sqlteam.com/SearchResults.asp?SearchTerms=csv

Particularly graz's article:

http://www.sqlteam.com/item.asp?ItemID=637

Go to Top of Page

gdeconto
Posting Yak Master

107 Posts

Posted - 2002-03-07 : 12:13:00
thx, Rob. it is close to what I need but not quite.

after looking at the problem more, realized that I needed to send in a list of keys and their values

ie similar to web URLs such as

?param1=value1,param2=value2,param3=value3 etc

is there an optimal approach to parsing this lind of list of parameters??

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-03-07 : 12:35:35
Do you have some code that shows how you use the pairs (any code at all)? I would almost suggest that you could pass the pairs in such a way that they make up part of the SQL statement, then you can dynamically execute it. I can't say for sure because this may not make sense for a SELECT or INSERT statement, but be perfect for an UPDATE or DELETE.

Even if that doesn't quite do it, you could modify the CSV parsing to parse out each pair, then parse the name and value, then construct dynamic SQL from the results.

Go to Top of Page

gdeconto
Posting Yak Master

107 Posts

Posted - 2002-03-08 : 11:53:25
yeah, that's the conclusion that I came up with as well.

I ended up building the query filter and string in my ASP app and then passing it to sql for execution.

thx for the help, dude.

Go to Top of Page
   

- Advertisement -