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 &copyToFacility
*/
INSERT
INTO IER_CERTIFICATIONS
  (
    EMPLOYEE_ID,
    CERTIFICATION,
    EXP_DATE,
    CERT_TITLE,
    CERT_BODY,
    DATE_MODIFIED,
    FACILITY
  )
  (SELECT
      &copyToEmplID AS EMPLOYEE_ID,
      CERTIFICATION,
      EXP_DATE,
      CERT_TITLE,
      CERT_BODY,
      DATE_MODIFIED,
      '&copyToFacility' AS FACILITY
    FROM IER_CERTIFICATIONS
    WHERE EMPLOYEE_ID =
      &copyFromEmplID
  );
/*
* duplicate users ier COMMUNITY from SMH to &copyToFacility
*/
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,
      &copyToEmplID AS EMPLOYEE_ID,
      EVENT_NAME,
      DATE_MODIFIED,
      END_DATE,
      '&copyToFacility' AS FACILITY
    FROM IER_COMMUNITY
    WHERE EMPLOYEE_ID =
      &copyFromEmplID
  );
/*
* duplicate users ier COURSES from SMH to &copyToFacility
*/
INSERT
INTO IER_COURSES
  (
    COURSE,
    COLLEGE,
    END_DATE,
    ROLE,
    EMPLOYEE_ID,
    HOURS,
    DATE_MODIFIED,
    FACILITY
  )
  (SELECT COURSE,
      COLLEGE,
      END_DATE,
      ROLE,
      &copyToEmplID AS EMPLOYEE_ID,
      HOURS,
      DATE_MODIFIED,
      '&copyToFacility' AS FACILITY
    FROM IER_COURSES
    WHERE EMPLOYEE_ID =
      &copyFromEmplID
  );
/*
* duplicate users ier DEGREE from SMH to &copyToFacility
*/
INSERT
INTO IER_DEGREE
  (
    EMPLOYEE_ID,
    DEGREE_TYPE,
    NURSING,
    MAJOR,
    GRAD_YEAR,
    COLLEGE,
    DATE_MODIFIED,
    FACILITY
  )
  (SELECT
      &copyToEmplID AS EMPLOYEE_ID,
      DEGREE_TYPE,
      NURSING,
      MAJOR,
      GRAD_YEAR,
      COLLEGE,
      DATE_MODIFIED,
      '&copyToFacility' AS FACILITY
    FROM IER_DEGREE
    WHERE EMPLOYEE_ID =
      &copyFromEmplID
  );
/*
* duplicate users ier HONORS from SMH to &copyToFacility
*/
INSERT
INTO IER_HONORS
  (
    AWARD,
    ORGANIZATION,
    AWARD_MONTH,
    EMPLOYEE_ID,
    DATE_MODIFIED,
    FACILITY,
    AWARD_YEAR
  )
  (SELECT AWARD,
      ORGANIZATION,
      AWARD_MONTH,
      &copyToEmplID AS EMPLOYEE_ID,
      DATE_MODIFIED,
      '&copyToFacility' AS FACILITY,
      AWARD_YEAR
    FROM IER_HONORS
    WHERE EMPLOYEE_ID =
      &copyFromEmplID
  );
/*
* duplicate users ier INSERVICE from SMH to &copyToFacility
*/
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,
      &copyToEmplID AS EMPLOYEE_ID,
      DATE_MODIFIED,
      CONTACT,
      '&copyToFacility' AS FACILITY
    FROM IER_INSERVICE
    WHERE EMPLOYEE_ID =
      &copyFromEmplID
  );
/*
* duplicate users ier LIFE_CERTS from SMH to &copyToFacility
*/
INSERT
INTO IER_LIFE_CERTS
  (
    EMPLOYEE_ID,
    CERT_CODE,
    EXP_DATE,
    ROLE,
    DATE_MODIFIED,
    FACILITY
  )
  (SELECT
      &copyToEmplID AS EMPLOYEE_ID,
      CERT_CODE,
      EXP_DATE,
      ROLE,
      DATE_MODIFIED,
      '&copyToFacility' AS FACILITY
    FROM IER_LIFE_CERTS
    WHERE EMPLOYEE_ID =
      &copyFromEmplID
  );
/*
* duplicate users ier ORGANIZATIONS from SMH to &copyToFacility
*/
INSERT
INTO IER_ORGANIZATIONS
  (
    POSITION,
    START_DATE,
    ORG_NAME,
    EMPLOYEE_ID,
    DATE_MODIFIED,
    END_DATE,
    FACILITY,
    SETTING
  )
  (SELECT POSITION,
      START_DATE,
      ORG_NAME,
      &copyToEmplID AS EMPLOYEE_ID,
      DATE_MODIFIED,
      END_DATE,
      '&copyToFacility' AS FACILITY,
      SETTING
    FROM IER_ORGANIZATIONS
    WHERE EMPLOYEE_ID =
      &copyFromEmplID
  );
/*
* duplicate users ier PRESENTATIONS from SMH to &copyToFacility
*/
INSERT
INTO IER_PRESENTATIONS
  (
    EMPLOYEE_ID,
    DATE_MODIFIED,
    AUTHORS,
    TITLE,
    CONFERENCE,
    CITY,
    STATE,
    SETTING,
    PRES_DATE,
    PRES_TYPE,
    FACILITY
  )
  (SELECT
      &copyToEmplID AS EMPLOYEE_ID,
      DATE_MODIFIED,
      AUTHORS,
      TITLE,
      CONFERENCE,
      CITY,
      STATE,
      SETTING,
      PRES_DATE,
      PRES_TYPE,
      '&copyToFacility' AS FACILITY
    FROM IER_PRESENTATIONS
    WHERE EMPLOYEE_ID =
      &copyFromEmplID
  );
/*
* duplicate users ier PUBLICATIONS from SMH to &copyToFacility
*/
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
      &copyToEmplID 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,
      '&copyToFacility' AS FACILITY
    FROM IER_PUBLICATIONS
    WHERE EMPLOYEE_ID =
      &copyFromEmplID
  );
/*
* duplicate users ier TEAMS from SMH to &copyToFacility
*/
INSERT
INTO IER_TEAMS
  (
    EMPLOYEE_ID,
    TEAM_NAME,
    MY_ROLE,
    DATE_MODIFIED,
    ACTIVE_YEAR,
    FACILITY,
    SETTING
  )
  (SELECT
      &copyToEmplID AS EMPLOYEE_ID,
      TEAM_NAME,
      MY_ROLE,
      DATE_MODIFIED,
      ACTIVE_YEAR,
      '&copyToFacility' AS FACILITY,
      SETTING
    FROM IER_TEAMS
    WHERE EMPLOYEE_ID =
      &copyFromEmplID
  );

以上是关于sql 这将从一个员工ID和工具复制数据库中的所有条目到另一个。用于在员工h时复制IER记录的主要内容,如果未能解决你的问题,请参考以下文章

如何将文件表与SQL Server中的现有表链接

SQL:如何在数据库中的所有视图中搜索 ID 并列出提供结果的视图和列名称? [复制]

跟踪员工在办公室时间查询 - Oracle SQL Developer

sql 这将获得员工的姓名,身份,时间(生产和非生产),日期工作以及所提供单位的任何理由。

尝试使用 sql 在单行中获取结果? [复制]

为每个 ID 乘以一组日期