INSERT INTO GIADM.GI_TRANSFER_EMP(TRANSFER_EMP_ID,USER_ID,EMP_LAST_NAME,
EMP_FIRST_NAME,EMP_ACTIVE_FLAG)
VALUES (select a.USER_ID as transfer_emp_id,
u.user_id as user_id,
u.user_last_name as emp_last_name,
u.USER_FIRST_NAME as emp_first_name,
u.USER_ACTIVE_FLAG as emp_active_flag
from db_user u, application_group_user a
where u.user_id in
(select a.user_id
from application_group_user a
WHERE a.APP_ID = 46
and a.SEC_GROUP_ID = 17)
and a.user_id = u.user_id);
views:
42answers:
2
+2
A:
Don't need the VALUES keyword when you're using SELECT to populate an INSERT statement:
INSERT INTO GIADM.GI_TRANSFER_EMP
(TRANSFER_EMP_ID,USER_ID,EMP_LAST_NAME,EMP_FIRST_NAME,EMP_ACTIVE_FLAG)
SELECT a.USER_ID as transfer_emp_id,
u.user_id as user_id,
u.user_last_name as emp_last_name,
u.USER_FIRST_NAME as emp_first_name,
u.USER_ACTIVE_FLAG as emp_active_flag
FROM DB_USER u
JOIN APPLICATION_GROUP_USER a ON a.user_id = u.user_id
AND a.APP_ID = 46
AND a.SEC_GROUP_ID = 17
OMG Ponies
2010-09-22 17:15:10
+4
A:
The syntax is either
INSERT INTO tablename (columnnames...) VALUES (values...)
or
INSERT INTO tablename (columnnames...)
SELECT values
FROM ...
devio
2010-09-22 17:15:40