首页 文章

带有Select和Parameter的SQL插入

提问于
浏览
0

你好我有问题

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


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

我怎么解决这个问题

Insert
Table1.Column1 = Table2.Column1
Table1.Column2 =是table2.column2
Table1.Column3=@target_date

2 回答

  • 1
    declare @target_date datetime
    set @target_date=GETDATE();
    
    
    insert into table1 ([column1],[column2],[column3])
    select [column1],[column2], @target_date from table2 where id=@id
    

    只需将变量设为计算列的值即可

  • 0

    插入后你不需要()for select命令,你必须在select命令中移动@target_date .

相关问题