1
votes

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.

2

2 Answers

2
votes

That's a pretty straightforward insert:

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

Try this:

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