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