我在 SQL 中有两个表,每个表分别有 12 和 16 列。这 4 个在两者中都很常见。
我需要的是我希望将一个表中这 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 EMPLOYEECODE=@EMPLOYEECODE ) ,
@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.