Detecting Duplicates by Reference Code
In some scenarios, you need to ensure that a reference code is completely unique among a record type.
 
To do this, use the following SQL script:
- --Look for duplicate records in the __M_Matters table
 - SELECT
 -     *
 - FROM
 -     --Change this to the table we want to identify duplicates in
 -     __M_Matters V1,
 -     (
 -         SELECT
 -             Final_ReferenceCode,
 -             COUNT(*) as Duplicates
 -         FROM
 -             __M_Matters --This needs to match the same table as above
 -         GROUP BY
 -             Final_ReferenceCode
 -         HAVING 
 -             COUNT(*) > 1
 -      ) V2
 - WHERE 1=1
 -     AND V1.Final_ReferenceCode = V2.Final_ReferenceCode
 - ORDER BY
 -     V1.Final_ReferenceCode
 
Related Articles
 
Matters: Trimming Client Numbers from Matter Numbers
The following script will peel off client numbers from matter numbers. For example, if a matter has a ReferenceCode like: ABC-0001 After the script runs, it will have a reference code of: 0001 Scenario 1: There are Client Reference Codes In some ...
 
SQL Spreadsheets: DocType Mappings
The following SQL script will generate a Google Spreadsheet that will allow users to override document category names. This is extremely helpful when merging systems. SELECT V1.Id, V1.Final_ReferenceCode as 'Old Code', V1.Final_Subject as 'Old Name', ...
 
Deduplicate Matter Participating Entities
Some systems will have the same entity (contact, user, etc...) associated with a matter multiple times with exactly the same role. If the signature of the relationship is exactly the same, the following script will eliminate the duplicates. ...
 
Audit Scripts: Row Counts and Progress Monitoring
This article shows you a script that can be used to monitor the progress of both a Backup and a Restore. It can also be used to just review row counts on all the Universal Database tables. The first code block is used to populate a SQL Server Temp ...
 
Convert User-Select/Contact-Select Custom Fields => Participants
Some systems do not support User-Select or Contact Select custom fields. The following query will transform User-Select fields into Matter Participants. This script can easily be adapted for Contact-Select fields. -- Transform Custom Fields on ...