|
![]() |
Property | Value |
Name | usp_DimPositionLoad_DupKeyCheck |
Schema | dbo |
Is Encrypted | False |
Ansi Nulls Status | True |
Quoted Identifier Status | True |
Description |
Name | Data Type | Direction | Description |
Name | Type |
Table |
Name | Type |
TABLE |
Object | Property | Value |
Object | Property | Value |
/****** Object: StoredProcedure [dbo].[usp_DimPositionLoad_DupKeyCheck] Script Date: 03/09/2017 17:21:49 ******/ SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON /* Primary Student Term Source SELECT Statement including Incremental Modifications*/ CREATE PROC [dbo].[usp_DimPositionLoad_DupKeyCheck] AS SET NOCOUNT ON -- Create in-memory table for later use within this proc CREATE TABLE #Position_Dup ( [PositionAK] VARCHAR(16) NOT NULL ) -- populate table with duplicate PositionAK values INSERT INTO #Position_Dup ( [PositionAK] ) select PositionAK from Verify_dbo_DimPosition group by PositionAK having COUNT(PositionAK) > 1 --Detect duplicate records and set flag UPDATE Verify_dbo_DimPosition SET RowIsDuplicate = 'Y' FROM Verify_dbo_DimPosition WHERE PositionAK IN ( select PositionAK from #Position_Dup ); --Set RowIsSelected = N for duplicated records (detected above) UPDATE RecordsToIgnore SET RowIsSelected = 'N' FROM dbo.Verify_dbo_DimPosition RecordsToIgnore INNER JOIN ( --Returns the first record for a set of duplicated OrgUnit --(as defined as minimum of surrogate key of temp table) SELECT PositionAK, MIN(VerifyPositionSK) as Min_VerifyPositionSK FROM Verify_dbo_DimPosition WHERE PositionAK in ( select PositionAK from #Position_Dup ) GROUP BY PositionAK ) as Keeper ON ( Keeper.PositionAK = RecordsToIgnore.PositionAK AND Keeper.Min_VerifyPositionSK <> RecordsToIgnore.VerifyPositionSK ) WHERE RecordsToIgnore.RowIsDuplicate = 'Y'; |
Powered by BI Documenter |