b1nary0mega
6/5/2014 - 8:02 PM

This will duplicate all entries in a database from one employee id and facility to another. Used to copy over IER records when an employee h

This will duplicate all entries in a database from one employee id and facility to another. Used to copy over IER records when an employee holds dual positions at 2 facilities which utilize different employee ids.

/*
* 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
  );