I have two table in SQL, each having 12 and 16 columns respectively.Out of these 4 are common in both.
What I need is that I want values of these 4 columns from one table to be inserted to the columns in another table.
I tried the following:
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())
Other column values are passed by parameters from my application but the four columns i.e IDGRADE,IDDEPARTMENT,IDDESIGNATION,EMPLOYEE_EMAIL
I want from another table.
Can this be done???? I need some help here.
Update: The above query when run gives the following error:
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.