0

Hello I have a problem

declare @target_date datetime
set @target_date=GETDATE();


insert into table1 ([column1],[column2],[column3])
(select [column1],[column2] from table2 where id=@id), @target_date

How can I solve this problem

Insert
Table1.Column1=Table2.Column1
Table1.Column2=Table2.Column2
Table1.Column3=@target_date

BK52
  • 754
  • 2
  • 11
  • 33

2 Answers2

3
declare @target_date datetime
set @target_date=GETDATE();


insert into table1 ([column1],[column2],[column3])
select [column1],[column2], @target_date from table2 where id=@id

Just make the variable the value of a calculated column

Matt
  • 13,833
  • 2
  • 16
  • 28
0

you don't need () for select command after insert, and you have to move @target_date inside the select command.

Karvan
  • 250
  • 2
  • 7
  • Technically you would be correct, though I have already answered that way. It would be good in the future to show the actual change via code rather than a straight narrative it is easier for others to follow your answer that way. – Matt Nov 14 '16 at 17:42