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

2 Answers 2

4
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

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.