我有一个员工表,从中可以根据用户ID查找主管(团队负责人)和经理的详细信息。我有一个SSIS包,它将新创建的Users附加到表中。 以下是我目前正在做的事情。
现在,当现有员工更改其经理或主管时,如何将新更改从主表更新到sql表。我不想截断并加载该表,因为该表已在应用程序中使用。
查询如下:
-加载新员工详细信息
INSERT INTO [dbo].[Active_Directory_COE]
(
[USER_ID]
, [USER_TYPE_NM]
, [USER_CLASS]
, [LAST_NM]
, [FIRST_NM]
, [MIDDLE_INIT]
, [EMAIL_ADDRESS]
, [EMP_JOB_DESC]
, [BUSINESS_UNIT_CD]
, [BUSINESS_UNIT_NM]
, [BUSINESS_SEGMENT]
, [SUPERVISOR_ID]
, [EMP_FULL_NM]
, [MANAGER_NAME]
, [SUPERVISOR_NAME]
, [SUPERVISOR_EMAIL_ADDRESS]
, [MANAGER_EMAIL_ADDRESS]
, [TEAM]
, [REGION]
, [SUB_REGION]
, [SALES_OFFICE]
, [SALES_GROUP]
, [EMPLOYEE_STATUS]
, [SURVEY_GROUP]
, [SURVEY_APPLICABLE]
, [REGION_CSSC]
, [SALES_ORG]
, [SALES_OFFICE_MULTIPLE]
, [TE_JOINING_DT]
)
SELECT
[A1].[USER_ID]
, [A1].[USER_TYPE_NM]
, [A1].[USER_CLASS]
, [A1].[LAST_NM]
, [A1].[FIRST_NM]
, [A1].[MIDDLE_INIT]
, [A1].[EMAIL_ADDRESS]
, [A1].[EMP_JOB_DESC]
, [A1].[BUSINESS_UNIT_CD]
, [A1].[BUSINESS_UNIT_NM]
, [A1].[BUSINESS_SEGMENT]
, [A1].[SUPERVISOR_ID]
, [A1].[EMP_FULL_NM]
, [D].[EMP_FULL_NM] AS [Manager_Name]
, [C].[EMP_FULL_NM] AS [Supervisor_name]
, [C].[EMAIL_ADDRESS] AS [Supr_Email_AD]
, [D].[EMAIL_ADDRESS] AS [Mangaer_Email_Ad]
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, [A1].[SERVICE_CREDIT_DT]
FROM
(
SELECT
[A].[USER_ID]
, [A].[USER_TYPE_NM]
, [A].[USER_CLASS]
, [A].[LAST_NM]
, [A].[FIRST_NM]
, [A].[MIDDLE_INIT]
, [A].[EMAIL_ADDRESS]
, [A].[EMP_JOB_DESC]
, [A].[BUSINESS_UNIT_CD]
, [A].[BUSINESS_UNIT_NM]
, [A].[BUSINESS_SEGMENT]
, [A].[SUPERVISOR_ID]
, [A].[EMP_FULL_NM]
, [A].[SERVICE_CREDIT_DT]
FROM [dbo].[Active_Directory] [A]
LEFT OUTER JOIN [dbo].[Active_Directory_COE] [B]
ON [A].[USER_ID] = [B].[USER_ID]
WHERE [B].[USER_ID] IS NULL
) [A1]
INNER JOIN [dbo].[Active_Directory] [C]
ON [C].[USER_ID] = [A1].[SUPERVISOR_ID]
INNER JOIN [dbo].[Active_Directory] [D]
ON [C].[SUPERVISOR_ID] = [D].[USER_ID];