How do pass Select results into sproc | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

How do pass Select results into sproc


What is optimal way to do this? I have table variable with one row of data. I need to pass the columns into a stored procedure. so lets say my table is: declare @table table ( col1 int, col2 int, col3 int) insert @table (col1, col2, col2)
values ( 1, 2, 3)
exec myproc @var1 = 1, @var2 = 2, @var3 = 3
Is there a way I can do a select * from @table and pass the results directly into the sproc, or do I need to assign each into a variable first and pass them in that way?

Other then populated scalar variables directly (recommended) you can also create table function, but I don’t see the purpose of either single-row table variable or table function returning allways just one row.
Can’t you pass the table variable as one of the parameters?

How would I pass a table variable into another proc?
quote:Originally posted by Tom Leykis
How would I pass a table variable into another proc?
You can’t. You might want to use global temp table. ——
> KH <
See if this helps:http://www.sommarskog.se/share_data.html
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs
Ich unterstuetze PASS Deutschland e.V. http://www.sqlpass.de)
Hm, thanks for reminding me about not being able to use a table variable as a procedure parameter – I should have known. I seem to remember though that this is written somewhere in BOL – can’t seem to find it! Any ideas?
]]>