我在SQL中有两个表,每个表分别具有12列和16列。这四个中的两个都是常见的。将特定列的值从一个表插入到另一个表中的特定列
我需要的是我希望从一个表中的这4列的值插入到另一个表的列中。
我试过如下:
INSERT INTO TABLE2 (IDCOMPANY,
IDPLANT,
IDTRAINING,
IDEMPLOYEE,
IDGRADE,
IDDEPARTMENT,
IDDESIGNATION,
EMAIL,
STATUS,
CREATEDBY,
CREATEDON)
VALUES (@IDCOMPANY,
@IDPLANT,
@IDTRAINING,
@IDEMPLOYEE,
(SELECT IDGRADE,
IDDEPARTMENT,
IDDESIGNATION,
EMPLOYEE_EMAIL
FROM TABLE1
WHERE [email protected]) ,
@STATUS,
@CREATEDBY,
GETDATE())
其他列的值从我的应用程序参数传递,但四列即IDGRADE,IDDEPARTMENT,IDDESIGNATION,EMPLOYEE_EMAIL
我从另一个表希望。
可以这样做吗?我需要一些帮助。
更新:在运行时提供了以下错误上面的查询:
Msg 116, Level 16, State 1, Procedure USP_INSERT_HR, Line 219
Only one expression can be specified in the select list when the subquery
is not introduced with EXISTS.
Msg 109, Level 15, State 1, Procedure USP_INSERT_HR, Line 217
There are more columns in the INSERT statement than values specified in
the VALUES clause. The number of values in the VALUES clause must match the
number of columns specified in the INSERT statement.