You need to create a temporary table to store the results of the stored process and then merge the results into a table. A temporary table is recommended for a table variable, since it will work better with an existing table due to better statistics.
CREATE TABLE #TempResults ( Field1 DATATYPE1, Field2 DATATYPE2, ..., PRIMARY KEY CLUSTERED (KeyField1,...) ) INSERT INTO #TempResults (Field1, Field2, ...) EXEC Schema.ProcName @Param1, ...
Now there are two ways to merge. The first works in all versions of SQL Server, and the second uses the command that was introduced in SQL Server 2008.
-- this should work on all SQL SERVER versions UPDATE rt SET rt.Field2 = tmp.Field2, ... FROM Schema.RealTable rt INNER JOIN
OR
-- the MERGE command was introduced in SQL SERVER 2008 MERGE Schema.RealTable AS target USING (SELECT Field1, Field2,... FROM
More information about the MERGE team can be found here:
http://msdn.microsoft.com/en-us/library/bb510625(v=SQL.100).aspx
Now, if you have a large result set for joining, and the table you merge into is very large and has a lot of activity on it, where this type of operation can cause some lock, then it can be looped to make sets of 1000 rows per times or something like that. Something like that:
<insert CREATE TABLE / INSERT...EXEC block> CREATE TABLE
source share