Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert results from a stored procedure into a table variable

Status
Not open for further replies.

Craigmacs

Programmer
Nov 7, 2002
35
CA
Is there a way to insert results from a stored procedure into a table variable. The following does not work.
(sp is a stored procedure with one numeric parameter)

declare @sql as nvarchar(200)
declare @tablevar table
(a Char(10),
b int,
c Numeric(5,2),
d Numeric(5,2))

set @sql = 'insert into '+ @tablevar + ' exec sp 2002'
exec sp_executesql @sql


I pretty sure a table variable is not available in the dynamic sql. Any other idea's on how to get the results of a sp inserted into a table variable?

Thanks
 
A table variable cannot be used like that. From BOL - table variables ...

Within its scope, a table variable may be used like a regular table. It may be applied anywhere a table or table expression is used in SELECT, INSERT, UPDATE, and DELETE statements. However, table may not be used in the following statements:

INSERT INTO table_variable EXEC stored_procedure


--Angel [rainbow]
-----------------------------------
Every time I lose my mind, I wonder
if it's really worth finding.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top