|
![]() |
Property | Value |
Name | usp_DimProgramRetentionCohortLoad_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_DimProgramRetentionCohortLoad_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_DimProgramRetentionCohortLoad_DupKeyCheck] AS SET NOCOUNT ON -- Create in-memory table for later use within this proc CREATE TABLE #Stdnt_Cohort_Dup ( [ProgramRetentionCohortAK] VARCHAR(30) NOT NULL ) -- populate table with duplicate StudentSuccessCohortAK values INSERT INTO #Stdnt_Cohort_Dup ( [ProgramRetentionCohortAK] ) select ProgramRetentionCohortAK from Verify_dbo_DimProgramRetentionCohort group by ProgramRetentionCohortAK having COUNT(ProgramRetentionCohortAK) > 1 --Detect duplicate records and set flag UPDATE Verify_dbo_DimProgramRetentionCohort SET RowIsDuplicate = 'Y' FROM Verify_dbo_DimProgramRetentionCohort WHERE ProgramRetentionCohortAK IN ( select ProgramRetentionCohortAK from #Stdnt_Cohort_Dup ); --Set RowIsSelected = N for duplicated records (detected above) UPDATE RecordsToIgnore SET RowIsSelected = 'N' FROM dbo.Verify_dbo_DimProgramRetentionCohort RecordsToIgnore INNER JOIN ( --Returns the first record for a set of duplicated StudentTerms --(as defined as minimum of surrogate key of temp table) SELECT ProgramRetentionCohortAK, MIN(VerifyProgramRetentionCohortSK) as Min_VerifyProgramRetentionCohortSK FROM Verify_dbo_DimProgramRetentionCohort WHERE ProgramRetentionCohortAK in ( select ProgramRetentionCohortAK from #Stdnt_Cohort_Dup ) GROUP BY ProgramRetentionCohortAK ) as Keeper ON ( Keeper.ProgramRetentionCohortAK = RecordsToIgnore.ProgramRetentionCohortAK AND Keeper.Min_VerifyProgramRetentionCohortSK <> RecordsToIgnore.VerifyProgramRetentionCohortSK ) WHERE RecordsToIgnore.RowIsDuplicate = 'Y'; |
Powered by BI Documenter |