我想从表中插入一个变量值和一个选择结果。
declare @actual Date
set @actual = getdate()
这是我的尝试:
insert into test (ID, Date) (select ID, @actual from Table)
我收到错误消息!!
答案 0 :(得分:3)
使用INSERT INTO..SELECT
语句,
DECLARE @actual Date
SET @actual = GETDATE()
INSERT INTO test (ID, Date)
SELECT ID, @actual
FROM Tablename
答案 1 :(得分:1)
You can try like this for using a select clause for Insert
insert into test(id,date) select col1,col2 from table;
答案 2 :(得分:0)
INSERT INTO TEST
(ID,DATE)
SELECT COLUMN1,COLUMN2 FROM TABLE