Integration.MigrateStagedEmployeeData
Documentation | WideWorldImportersDW |
Schema | Integration |
Name | MigrateStagedEmployeeData |
Script
CREATE PROCEDURE Integration.MigrateStagedEmployeeData WITH EXECUTE AS OWNER AS BEGIN SET NOCOUNT ON; SET XACT_ABORT ON; DECLARE @EndOfTime datetime2(7) = '99991231 23:59:59.9999999'; BEGIN TRAN; DECLARE @LineageKey int = (SELECT TOP(1) [Lineage Key] FROM Integration.Lineage WHERE [Table Name] = N'Employee' AND [Data Load Completed] IS NULL ORDER BY [Lineage Key] DESC); WITH RowsToCloseOff AS ( SELECT e.[WWI Employee ID], MIN(e.[Valid From]) AS [Valid From] FROM Integration.Employee_Staging AS e GROUP BY e.[WWI Employee ID] ) UPDATE e SET e.[Valid To] = rtco.[Valid From] FROM Dimension.Employee AS e INNER JOIN RowsToCloseOff AS rtco ON e.[WWI Employee ID] = rtco.[WWI Employee ID] WHERE e.[Valid To] = @EndOfTime; INSERT Dimension.Employee ([WWI Employee ID], Employee, [Preferred Name], [Is Salesperson], Photo, [Valid From], [Valid To], [Lineage Key]) SELECT [WWI Employee ID], Employee, [Preferred Name], [Is Salesperson], Photo, [Valid From], [Valid To], @LineageKey FROM Integration.Employee_Staging; UPDATE Integration.Lineage SET [Data Load Completed] = SYSDATETIME(), [Was Successful] = 1 WHERE [Lineage Key] = @LineageKey; UPDATE Integration.[ETL Cutoff] SET [Cutoff Time] = (SELECT [Source System Cutoff Time] FROM Integration.Lineage WHERE [Lineage Key] = @LineageKey) FROM Integration.[ETL Cutoff] WHERE [Table Name] = N'Employee'; COMMIT; RETURN 0; END; |
Exported: 2019-02-04 23:05, Last imported: 2018-08-10 09:59