DWOperations
 usp_DimStudentObjectiveLoad_DupKeyCheck (Stored Procedure)
  Properties
Property Value
Name usp_DimStudentObjectiveLoad_DupKeyCheck
Schema dbo
Is Encrypted False
Ansi Nulls Status True
Quoted Identifier Status True
Description
  Parameters
Name Data Type Direction Description
  Parent Dependencies (objects that usp_DimStudentObjectiveLoad_DupKeyCheck depends on)
Name Type
Table
  Child Dependencies (objects that depend on usp_DimStudentObjectiveLoad_DupKeyCheck)
Name Type
TABLE
  Extended Properties
Object Property Value
   Annotations
Object Property Value
  DDL
/****** Object: StoredProcedure [dbo].[usp_DimStudentObjectiveLoad_DupKeyCheck] Script Date: 03/09/2017 17:21:49 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
/*
Name:            usp_DimStudentObjectiveLoad_DupKeyCheck
Title:            Mark Duplicate Student Objective Dimension
Date:            05/21/2013
System/Project:    Executive Dashboard - Graduation
Description:    This procedure will mark duplicate Student Objective records and which one to select.
Revision History:
*/
/* Primary Student Term Source SELECT Statement including Incremental Modifications*/
CREATE PROC [dbo].[usp_DimStudentObjectiveLoad_DupKeyCheck]
AS 
SET NOCOUNT ON
-- Create in-memory table for later use within this proc
CREATE TABLE #Stdnt_Objective_Dup
    (
    [StudentObjectiveAK] VARCHAR(23) NOT NULL
    )
-- populate table with duplicate StudentObjectiveAK values
INSERT INTO #Stdnt_Objective_Dup
    (
    [StudentObjectiveAK]
    )
    select StudentObjectiveAK
    from Verify_dbo_DimStudentObjective
    group by StudentObjectiveAK
    having COUNT(StudentObjectiveAK) > 1
    
--Detect duplicate records and set flag
UPDATE Verify_dbo_DimStudentObjective
SET RowIsDuplicate = 'Y'
FROM Verify_dbo_DimStudentObjective
WHERE StudentObjectiveAK 
IN
 (
 select StudentObjectiveAK
 from #Stdnt_Objective_Dup
 );
--Set RowIsSelected = N for duplicated records (detected above)
UPDATE RecordsToIgnore
SET RowIsSelected = 'N'
FROM dbo.Verify_dbo_DimStudentObjective RecordsToIgnore
INNER JOIN
 (
 --Returns the first record for a set of duplicated StudentObjectives
 --(as defined as minimum of surrogate key of temp table)
 SELECT StudentObjectiveAK, MIN(VerifyStudentObjectiveSK) as Min_VerifyStudentObjectiveSK
 FROM Verify_dbo_DimStudentObjective
 WHERE StudentObjectiveAK in
  (
    select StudentObjectiveAK
    from #Stdnt_Objective_Dup
  ) 
 GROUP BY StudentObjectiveAK 
 ) as Keeper
ON (
 Keeper.StudentObjectiveAK = RecordsToIgnore.StudentObjectiveAK
 AND
 Keeper.Min_VerifyStudentObjectiveSK <> RecordsToIgnore.VerifyStudentObjectiveSK
 )
WHERE RecordsToIgnore.RowIsDuplicate = 'Y';
Powered by BI Documenter