views:

46

answers:

1

Can anyone tell me how to insert a record in a table in the following case:

I have 2 tables:

create table #temp1(c4 int, c5 int,c3 int)

...and:

create table #temp2(c1 int, c2 int)


create procedure sptemp
as
begin
  select c1,c2 from #temp2
end


Now I want to insert records into #temp1 table using the procedure as:

insert into #temp1(c4,c5,c3)

In the above statement, first 2 values(c4,c5) should be from procedure(exec sptemp) and the third value will be using (ex: values(34)).

Please suggest me the way to implement.

+3  A: 

In Sql Server 2005 you can exec a sp into a table var

DECLARE @TBL TABLE(
     C1 INT,
     C2 INT
)

INSERT INTO @TBL (C1, C2) EXEC sptemp

SELECT *, 34 FROM @TBL
astander