Insert Values from Stored Procedure

24. May 2010

I was unaware that you could accomplish something like this so I thought I would add to the articles out there just in case this will help others for a situation similiar to mine.

I wrote a stored procedure that would or would not return a record result based off conditions.

I then needed to integrate that with another stored procedure to use the results from it.

Now, I could have probably just wrote a Table Value Function in SQL, but I am also using this stored procedure for other parts of the applications through out the system.  Anyway, this is how you can insert the values from a stored procedure into a table.

DECLARE @tmpTable TABLE 
(
   ID INT
    ,FirstName VARCHAR(100)
    ,LastName VARCHAR(100)
)

INSERT INTO @tmpTable 
EXEC [dbo].[GetSomeData]

SELECT * FROM @tmpTable

 

The thing I found is that the column count has to match for the temp table and the columns being returned from the stored procedure


Note: My environment for this was SQL 2005

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Microsoft SQL

blog comments powered by Disqus