I don’t believe this is possible, but want to confirm you cannot set a table variable from the results of executing a stored procedure in SQL Server 2008.
I was trying to do the following:
DECLARE @Results TABLE (RESULT_ID INT);
INSERT INTO @Results (RESULT_ID) VALUES (1);
SET @Results =
EXEC dbo.[spResultLookup] @Results;
My goal is to pass @Results to the stored procedure and then to replace @Results with results from the call to spResultLookup.
The alternative is to delete the rows in @Results and use an INSERT with EXEC statement.
Here’s a page from documentation that demonstrates how you can pass tables into procs but it definitely stipulates that you can’t update the table with DML.
http://msdn.microsoft.com/en-us/library/bb510489.aspx
Of course you could create a temp table that would be available in scope to the caller and the proc. This is probably what you have to resort to for your use case.