我有一个存储过程,我选择值并希望插入表
SELECT
@uid = arf.uid, @report_format = arf.report_format,
@report_serno = arf.report_serno
FROM
dbo.alert_report_format AS arf
INNER JOIN
dbo.users AS u ON arf.uid = u.serno
INNER JOIN
dbo.alert_reports AS ar ON arf.report_serno = ar.serno
在表格中插入:
INSERT INTO reports
VALUES (NULL, @uid, @subject, @body, @report_format, 100, @report_serno, 0, NULL, 10, GETDATE())
在select中我有5个值,但是当我插入另一个表onle插入最后选择的值时,我想要将所有值插入到表中我在select中有什么,如何在没有游标的情况下这样做?
答案 0 :(得分:4)
您需要使用类似
的内容INSERT INTO MyTable(Column1, Column2,.... ColumnN)
SELECT C1,C2,... CN
FRom MyTable
答案 1 :(得分:4)
尝试这种方式:
INSERT INTO reports
SELECT null,arf.uid, @subject, @body, arf.report_format, 100,arf.report_serno,0,NULL,10,GETDATE()
FROM dbo.alert_report_format AS arf
INNER JOIN dbo.users AS u ON arf.uid = u.serno
INNER JOIN dbo.alert_reports AS ar ON arf.report_serno = ar.serno