Friday, June 24, 2011

Inserting records output by the stored procedure

Let's say you have a stored procedure which returns some records from the product table:

create proc pr_test2
as
select prod_code, prod_description, price
from prod
go

So, when you execute pr_test2 stored procedure, the results is the products. In case you want to store these result into a table variable, you may do this:

declare @tb table(
prod_code nvarchar(100),
prod_description nvarchar(100), price money
)

insert into @tb
exec pr_test2

select * from @tb