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)
 Dynamic input variables for stored procs?

Author  Topic 

etietje
Starting Member

24 Posts

Posted - 2002-12-27 : 12:50:55
Hello.

I really need a way to have a random number of variables as inputs into a stored procedure. Is there a way to have a dynamic number of variables as inputs with SQL 2000? Thanks in advance for any help you can give me.

Eric

jasper_smith
SQL Server MVP & SQLTeam MVY

846 Posts

Posted - 2002-12-27 : 15:20:51
Why would they be random ? This sounds like a less than optimum approach as you could lose much of the benefit of a stored procedure (precompiled plan) and probably run into the "parameter sniffing" problem. You can assign a default of null to a procedure input parameter to make it optional. If you call the procedure with named parameters then you only need to specify the parameters you are supplying values for. However, maybe if you provide a bit more information you might get some suggestions on how to improve your procedure.


HTH
Jasper Smith
Go to Top of Page

etietje
Starting Member

24 Posts

Posted - 2002-12-27 : 16:21:29
Well, it really isn't anything fancy that I'm doing. I need to pass in a table name and then some number of columns. Then I need to do some processing using each of those columns separately. I have a stored proc now that accepts only one table and one column, but I would love to be able to put more than one column in the SP and just have the results returned one after the other. I don't send the results to any program or reporting tool, just in the query analyzer.

Go to Top of Page

skillile
Posting Yak Master

208 Posts

Posted - 2002-12-28 : 07:47:22
Post your SPROC and we can try to figure out what you need to accomplish

slow down to move faster...
Go to Top of Page

Onamuji
Aged Yak Warrior

504 Posts

Posted - 2002-12-28 : 08:39:26
why not use TEXT as your input and send in an XML document that then parses out the table name and all columns... this is how I handle dynamic queries that take an unknown number of parameters...

Go to Top of Page
   

- Advertisement -