|
![]() |
Property | Value |
Name | usp_DimTimeTypeLoad_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_DimTimeTypeLoad_DupKeyCheck] Script Date: 03/09/2017 17:21:49 ******/ SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON CREATE PROC [dbo].[usp_DimTimeTypeLoad_DupKeyCheck] AS SET NOCOUNT ON -- Create in-memory table for later use within this proc CREATE TABLE #TimeType_Dup ( [TimeTypeAK] VARCHAR(4) NOT NULL ) -- populate table with duplicate TimeTypeAK values INSERT INTO #TimeType_Dup ( [TimeTypeAK] ) select TimeTypeAK from Verify_dbo_DimTimeType group by TimeTypeAK having COUNT(TimeTypeAK) > 1 --Detect duplicate records and set flag UPDATE Verify_dbo_DimTimeType SET RowIsDuplicate = 'Y' FROM Verify_dbo_DimTimeType WHERE TimeTypeAK IN ( select TimeTypeAK from #TimeType_Dup ); --Set RowIsSelected = N for duplicated records (detected above) UPDATE RecordsToIgnore SET RowIsSelected = 'N' FROM dbo.Verify_dbo_DimTimeType RecordsToIgnore INNER JOIN ( --Returns the first record for a set of duplicated OrgUnit --(as defined as minimum of surrogate key of temp table) SELECT TimeTypeAK, MIN(VerifyTimeTypeSK) as Min_VerifyTimeTypeSK FROM Verify_dbo_DimTimeType WHERE TimeTypeAK in ( select TimeTypeAK from #TimeType_Dup ) GROUP BY TimeTypeAK ) as Keeper ON ( Keeper.TimeTypeAK = RecordsToIgnore.TimeTypeAK AND Keeper.Min_VerifyTimeTypeSK <> RecordsToIgnore.VerifyTimeTypeSK ) WHERE RecordsToIgnore.RowIsDuplicate = 'Y'; |
Powered by BI Documenter |