1

我想将变量中的值和选择结果插入表中。

declare @actual Date
set @actual = getdate()

这是我的尝试:

insert into test (ID, Date) (select ID, @actual from Table)

我收到一条错误消息!!

4

3 回答 3

4

使用INSERT INTO..SELECT声明,

DECLARE @actual Date
SET @actual = GETDATE()

INSERT INTO test (ID, Date) 
SELECT ID, @actual 
FROM   Tablename
于 2013-01-29T08:39:29.020 回答
1
You can try like this for using a select clause for Insert

insert into test(id,date) select col1,col2 from table;
于 2013-01-29T08:41:34.150 回答
0
INSERT INTO TEST
(ID,DATE)
SELECT COLUMN1,COLUMN2 FROM TABLE
于 2013-01-29T08:48:06.257 回答