如何在insert语句之前设置多个值?以下不起作用。
declare @foo int
declare @bar int
set (select @foo=foo, @bar=bar from Foobar where id=123);
insert into ...
select @foo, 3, @bar
答案 0 :(得分:1)
使用此 -
declare @foo int
declare @bar int
select @foo=foo, @bar=bar from Foobar where id=123;
insert into ...
select @foo, 3, @bar
答案 1 :(得分:1)
您可以使用SELECT
:
select @foo=foo, @bar=bar from Foobar where id=123;
或者,只需跳过变量并合并SELECT
and INSERT
:
insert into ...
select foo, bar
from Foobar
where id = 123;