|
![]() |
Property | Value |
Name | usp_DimStudentReceiptLoad_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_DimStudentReceiptLoad_DupKeyCheck] Script Date: 03/09/2017 17:21:49 ******/ SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON /* Name: usp_DimStudentReceiptLoad_DupKeyCheck Title: Mark Duplicate Student Receipt Dimension Date: 10/02/2013 System/Project: Executive Dashboard - Student Financials Description: This procedure will mark duplicate Student Receipt records and which one to select. Revision History: */ CREATE PROC [dbo].[usp_DimStudentReceiptLoad_DupKeyCheck] AS SET NOCOUNT ON -- Create in-memory table for later use within this proc CREATE TABLE #Stdnt_Receipt_Dup ( [StudentReceiptAK] VARCHAR(24) NOT NULL ) -- populate table with duplicate StudentReceiptAK values INSERT INTO #Stdnt_Receipt_Dup ( [StudentReceiptAK] ) select StudentReceiptAK from Verify_dbo_DimStudentReceipt group by StudentReceiptAK having COUNT(StudentReceiptAK) > 1 --Detect duplicate records and set flag UPDATE Verify_dbo_DimStudentReceipt SET RowIsDuplicate = 'Y' FROM Verify_dbo_DimStudentReceipt WHERE StudentReceiptAK IN ( select StudentReceiptAK from #Stdnt_Receipt_Dup ); --Set RowIsSelected = N for duplicated records (detected above) UPDATE RecordsToIgnore SET RowIsSelected = 'N' FROM dbo.Verify_dbo_DimStudentReceipt RecordsToIgnore INNER JOIN ( --Returns the first record for a set of duplicated StudentReceipt --(as defined as minimum of surrogate key of temp table) SELECT StudentReceiptAK, MIN(VerifyStudentReceiptSK) as Min_VerifyStudentReceiptSK FROM Verify_dbo_DimStudentReceipt WHERE StudentReceiptAK in ( select StudentReceiptAK from #Stdnt_Receipt_Dup ) GROUP BY StudentReceiptAK ) as Keeper ON ( Keeper.StudentReceiptAK = RecordsToIgnore.StudentReceiptAK AND Keeper.Min_VerifyStudentReceiptSK <> RecordsToIgnore.VerifyStudentReceiptSK ) WHERE RecordsToIgnore.RowIsDuplicate = 'Y'; |
Powered by BI Documenter |