Reputation: 1173
How do I set multiple values before an insert statement? The below doesnt work.
declare @foo int
declare @bar int
set (select @foo=foo, @bar=bar from Foobar where id=123);
insert into ...
select @foo, 3, @bar
Upvotes: 1
Views: 51
Reputation: 37398
You can assign the variables by using SELECT
:
select @foo=foo, @bar=bar from Foobar where id=123;
Or, just skip the variables and combine the SELECT
and INSERT
:
insert into ...
select foo, bar
from Foobar
where id = 123;
Upvotes: 1
Reputation: 149
Use this -
declare @foo int
declare @bar int
select @foo=foo, @bar=bar from Foobar where id=123;
insert into ...
select @foo, 3, @bar
Upvotes: 1