user219628
user219628

Reputation: 3905

T-SQL insert into tablewith values coming from QUERY + VARIABLE

I want to insert into table single record in one shot with values coming from QUERY + VARIABLE.

E.g. Insert into Table2(c1,c2,c3,c4)

c1,c2,c3 are coming from select col1,col2,col3 from Table1 c4 is coming from variable @var

As the volume of data is huge, I can not have one insert and second update.

Thanks in advance.

Upvotes: 1

Views: 2070

Answers (2)

Andomar
Andomar

Reputation: 238086

That's a pretty straightforward insert:

insert  Table2
        (c1, c2, c3, c4)
select  col1, col2, col3, @var
from    Table1

Upvotes: 2

Mark Byers
Mark Byers

Reputation: 838216

Try this:

INSERT INTO Table2 (c1,c2,c3,c4) 
SELECT col1, col2, col3, @var FROM table1

Upvotes: 2

Related Questions