如何在单个insert语句中将数据从存储过程,手动值一起插入表中

时间:2009-09-22 06:02:44

标签: sql sql-server sql-server-2005 tsql

在下列情况下,任何人都可以告诉我如何在表格中插入记录:

我有两张桌子:

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

......和:

create table #temp2(c1 int, c2 int)

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

现在我想使用以下过程将记录插入#temp1表:

insert into #temp1(c4,c5,c3)

在上面的陈述中,前2个值(c4,c5)应来自procedure(exec sptemp),第三个值将使用(ex:values(34))。

请建议我实施的方法。

1 个答案:

答案 0 :(得分:3)

在Sql Server 2005中,您可以将sp执行到表var

DECLARE @TBL TABLE(
        C1 INT,
        C2 INT
)

INSERT INTO @TBL (C1, C2) EXEC sptemp

SELECT *, 34 FROM @TBL
相关问题