1

如何在插入语句之前设置多个值?以下不起作用。

declare @foo int
declare @bar int
set (select @foo=foo, @bar=bar from Foobar where id=123);

insert into ...
select @foo, 3, @bar
4

2 回答 2

1

用这个 -

declare @foo int
declare @bar int
select @foo=foo, @bar=bar from Foobar where id=123;

insert into ...
select @foo, 3, @bar
于 2013-02-19T17:27:16.757 回答
1

您可以使用以下方法分配变量SELECT

select @foo=foo, @bar=bar from Foobar where id=123;

或者,只是跳过变量并结合SELECTandINSERT

insert into ...
select foo, bar
from Foobar
where id = 123;
于 2013-02-19T17:27:31.523 回答