Advertisement
DataCCIW

vCCIWPersonDuplicateList

Sep 22nd, 2022
1,833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.00 KB | None | 0 0
  1. /*
  2. ==========================================================================================================
  3. Title: vCCIWPersonDuplicateList
  4. Author: Tony Visconti
  5. Date: 9-22-22
  6. Description: builing a view that mirrors the personDuplicateQry dataset leveraged by the Person Duplicate List block.
  7. https://github.com/SparkDevNetwork/Rock/blob/develop/RockWeb/Blocks/Crm/PersonDuplicateList.ascx.cs
  8.  
  9. The block goes a step further and groups the results by Id. I don't want to do that in the view because
  10. I will be using it to calculate the number of records with a score > 60 and a score > 80. The number of
  11. records will be calculated via workflow that leverages this view and emails the count to the system admin.
  12.  
  13. Notes:
  14. // list duplicates that:
  15. // - aren't confirmed as NotDuplicate and aren't IgnoreUntilScoreChanges,
  16. // - don't have the PersonAlias and DuplicatePersonAlias records pointing to the same person ( occurs after two people have been merged but before the Calculate Person Duplicates job runs).
  17. // - don't include records where both the Person and Duplicate are inactive (block option)
  18. // - Default block options also
  19.  
  20. Change Log
  21.  
  22. ==========================================================================================================
  23. */
  24. CREATE VIEW [vCCIWPersonDuplicateList] AS
  25. SELECT p1.Id
  26.     ,p2.Id AS duplicatePersonId
  27.     ,pd.Id AS personDuplicateId
  28.     ,[PersonAliasId]
  29.     ,[DuplicatePersonAliasId]
  30.     ,[IsConfirmedAsNotDuplicate]
  31.     ,[Score]
  32.     ,[ScoreDetail]
  33.     ,[Capacity]
  34.     ,[IgnoreUntilScoreChanges]
  35.     ,[TotalCapacity]
  36.     ,[ConfidenceScore]
  37. FROM [dbo].[PersonDuplicate] pd
  38. JOIN [PersonAlias] pa1 ON pa1.Id = PersonAliasId
  39. JOIN [Person] p1 ON p1.Id = pa1.PersonId
  40. JOIN [PersonAlias] pa2 ON pa2.Id = DuplicatePersonAliasId
  41. JOIN [Person] p2 ON p2.Id = pa2.PersonId
  42.  
  43. WHERE IsConfirmedAsNotDuplicate = 0
  44.     AND IgnoreUntilScoreChanges = 0
  45.     AND pa1.PersonId <> pa2.PersonId
  46.     AND (
  47.         p1.RecordStatusValueId <> 4
  48.         OR p2.RecordStatusValueId <> 4
  49.         ) -- Where at least one record is active 4 = Inactive
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement