sql 这将从一个员工ID和工具复制数据库中的所有条目到另一个。用于在员工h时复制IER记录
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 这将从一个员工ID和工具复制数据库中的所有条目到另一个。用于在员工h时复制IER记录相关的知识,希望对你有一定的参考价值。
/*
* define some variables to make updating script easier
*/
DEFINE copyFromEmplID = 123456;
DEFINE copyToEmplID = 98765;
DEFINE copyToFacility = 'HH';
/*
* duplicate users ier CERTIFICATIONS from SMH to ©ToFacility
*/
INSERT
INTO IER_CERTIFICATIONS
(
EMPLOYEE_ID,
CERTIFICATION,
EXP_DATE,
CERT_TITLE,
CERT_BODY,
DATE_MODIFIED,
FACILITY
)
(SELECT
©ToEmplID AS EMPLOYEE_ID,
CERTIFICATION,
EXP_DATE,
CERT_TITLE,
CERT_BODY,
DATE_MODIFIED,
'©ToFacility' AS FACILITY
FROM IER_CERTIFICATIONS
WHERE EMPLOYEE_ID =
©FromEmplID
);
/*
* duplicate users ier COMMUNITY from SMH to ©ToFacility
*/
INSERT
INTO IER_COMMUNITY
(
START_DATE,
ORG_NAME,
MY_ROLE,
EMPLOYEE_ID,
EVENT_NAME,
DATE_MODIFIED,
END_DATE,
FACILITY
)
(SELECT START_DATE,
ORG_NAME,
MY_ROLE,
©ToEmplID AS EMPLOYEE_ID,
EVENT_NAME,
DATE_MODIFIED,
END_DATE,
'©ToFacility' AS FACILITY
FROM IER_COMMUNITY
WHERE EMPLOYEE_ID =
©FromEmplID
);
/*
* duplicate users ier COURSES from SMH to ©ToFacility
*/
INSERT
INTO IER_COURSES
(
COURSE,
COLLEGE,
END_DATE,
ROLE,
EMPLOYEE_ID,
HOURS,
DATE_MODIFIED,
FACILITY
)
(SELECT COURSE,
COLLEGE,
END_DATE,
ROLE,
©ToEmplID AS EMPLOYEE_ID,
HOURS,
DATE_MODIFIED,
'©ToFacility' AS FACILITY
FROM IER_COURSES
WHERE EMPLOYEE_ID =
©FromEmplID
);
/*
* duplicate users ier DEGREE from SMH to ©ToFacility
*/
INSERT
INTO IER_DEGREE
(
EMPLOYEE_ID,
DEGREE_TYPE,
NURSING,
MAJOR,
GRAD_YEAR,
COLLEGE,
DATE_MODIFIED,
FACILITY
)
(SELECT
©ToEmplID AS EMPLOYEE_ID,
DEGREE_TYPE,
NURSING,
MAJOR,
GRAD_YEAR,
COLLEGE,
DATE_MODIFIED,
'©ToFacility' AS FACILITY
FROM IER_DEGREE
WHERE EMPLOYEE_ID =
©FromEmplID
);
/*
* duplicate users ier HONORS from SMH to ©ToFacility
*/
INSERT
INTO IER_HONORS
(
AWARD,
ORGANIZATION,
AWARD_MONTH,
EMPLOYEE_ID,
DATE_MODIFIED,
FACILITY,
AWARD_YEAR
)
(SELECT AWARD,
ORGANIZATION,
AWARD_MONTH,
©ToEmplID AS EMPLOYEE_ID,
DATE_MODIFIED,
'©ToFacility' AS FACILITY,
AWARD_YEAR
FROM IER_HONORS
WHERE EMPLOYEE_ID =
©FromEmplID
);
/*
* duplicate users ier INSERVICE from SMH to ©ToFacility
*/
INSERT
INTO IER_INSERVICE
(
TITLE,
SETTING,
DURATION,
ROLE,
IS_DATE,
CONTACT_HRS,
EMPLOYEE_ID,
DATE_MODIFIED,
CONTACT,
FACILITY
)
(SELECT TITLE,
SETTING,
DURATION,
ROLE,
IS_DATE,
CONTACT_HRS,
©ToEmplID AS EMPLOYEE_ID,
DATE_MODIFIED,
CONTACT,
'©ToFacility' AS FACILITY
FROM IER_INSERVICE
WHERE EMPLOYEE_ID =
©FromEmplID
);
/*
* duplicate users ier LIFE_CERTS from SMH to ©ToFacility
*/
INSERT
INTO IER_LIFE_CERTS
(
EMPLOYEE_ID,
CERT_CODE,
EXP_DATE,
ROLE,
DATE_MODIFIED,
FACILITY
)
(SELECT
©ToEmplID AS EMPLOYEE_ID,
CERT_CODE,
EXP_DATE,
ROLE,
DATE_MODIFIED,
'©ToFacility' AS FACILITY
FROM IER_LIFE_CERTS
WHERE EMPLOYEE_ID =
©FromEmplID
);
/*
* duplicate users ier ORGANIZATIONS from SMH to ©ToFacility
*/
INSERT
INTO IER_ORGANIZATIONS
(
POSITION,
START_DATE,
ORG_NAME,
EMPLOYEE_ID,
DATE_MODIFIED,
END_DATE,
FACILITY,
SETTING
)
(SELECT POSITION,
START_DATE,
ORG_NAME,
©ToEmplID AS EMPLOYEE_ID,
DATE_MODIFIED,
END_DATE,
'©ToFacility' AS FACILITY,
SETTING
FROM IER_ORGANIZATIONS
WHERE EMPLOYEE_ID =
©FromEmplID
);
/*
* duplicate users ier PRESENTATIONS from SMH to ©ToFacility
*/
INSERT
INTO IER_PRESENTATIONS
(
EMPLOYEE_ID,
DATE_MODIFIED,
AUTHORS,
TITLE,
CONFERENCE,
CITY,
STATE,
SETTING,
PRES_DATE,
PRES_TYPE,
FACILITY
)
(SELECT
©ToEmplID AS EMPLOYEE_ID,
DATE_MODIFIED,
AUTHORS,
TITLE,
CONFERENCE,
CITY,
STATE,
SETTING,
PRES_DATE,
PRES_TYPE,
'©ToFacility' AS FACILITY
FROM IER_PRESENTATIONS
WHERE EMPLOYEE_ID =
©FromEmplID
);
/*
* duplicate users ier PUBLICATIONS from SMH to ©ToFacility
*/
INSERT
INTO IER_PUBLICATIONS
(
EMPLOYEE_ID,
DATE_MODIFIED,
PUB_DATE,
AUTHORS,
TITLE,
PUB_NAME,
PG_NUMBERS,
LINK,
PUB_TYPE,
CH_TITLE,
EDITOR,
PUBHOUSE_NAME,
PUBHOUSE_CITY,
PUBHOUSE_STATE,
ISSUE_NUMBER,
FACILITY
)
(SELECT
©ToEmplID AS EMPLOYEE_ID,
DATE_MODIFIED,
PUB_DATE,
AUTHORS,
TITLE,
PUB_NAME,
PG_NUMBERS,
LINK,
PUB_TYPE,
CH_TITLE,
EDITOR,
PUBHOUSE_NAME,
PUBHOUSE_CITY,
PUBHOUSE_STATE,
ISSUE_NUMBER,
'©ToFacility' AS FACILITY
FROM IER_PUBLICATIONS
WHERE EMPLOYEE_ID =
©FromEmplID
);
/*
* duplicate users ier TEAMS from SMH to ©ToFacility
*/
INSERT
INTO IER_TEAMS
(
EMPLOYEE_ID,
TEAM_NAME,
MY_ROLE,
DATE_MODIFIED,
ACTIVE_YEAR,
FACILITY,
SETTING
)
(SELECT
©ToEmplID AS EMPLOYEE_ID,
TEAM_NAME,
MY_ROLE,
DATE_MODIFIED,
ACTIVE_YEAR,
'©ToFacility' AS FACILITY,
SETTING
FROM IER_TEAMS
WHERE EMPLOYEE_ID =
©FromEmplID
);
以上是关于sql 这将从一个员工ID和工具复制数据库中的所有条目到另一个。用于在员工h时复制IER记录的主要内容,如果未能解决你的问题,请参考以下文章
SQL:如何在数据库中的所有视图中搜索 ID 并列出提供结果的视图和列名称? [复制]
跟踪员工在办公室时间查询 - Oracle SQL Developer