Matters: Trimming Client Numbers from Matter Numbers

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:

  1. ABC-0001

After the script runs, it will have a reference code of:

  1. 0001

 

Scenario 1: There are Client Reference Codes

In some systems, there are no Client reference codes.  This means that the Matter portion of the Matter's reference code needs to come by splitting based on a delimiter.

  1. --In this system, the Matter's ReferenceCode is prepended with
  2. --the Client's ReferenceCode and we don't want that.
  3. --However, Client's themselves dont have reference codes!
  4. --We are going to strip out everything past the first - in the matter's reference code.

  5. DECLARE @SEPARATOR nvarchar(MAX) = '-'

  6. UPDATE
  7. __M_Matters
  8. SET
  9. Final_ReferenceCode = SUBSTRING(Final_ReferenceCode, 1 + LEN(@SEPARATOR) + CHARINDEX(@SEPARATOR, Final_ReferenceCode), 99999)
  10. WHERE 1=1
  11. AND CharIndex(@SEPARATOR, Final_ReferenceCode) > 0

  12. GO


Scenario 2: There are No Client ReferenceCodes

In some systems, there are Client reference codes.  This means that the Matter portion of the Matter's reference code needs to come by splitting out on a delimiter.

  1. --In this system, the Matter's ReferenceCode is prepended with
  2. --the Client's ReferenceCode and we don't want that.
  3. --We are going to link matters to clients and then trim out the client reference codes.

  4. DECLARE @SEPARATOR nvarchar(MAX) = '-'

  5. UPDATE
  6. __M_Matters
  7. SET
  8. Final_ReferenceCode = Right(V2.Final_ReferenceCode, len(V2.Final_ReferenceCode) - len(V1.Final_ReferenceCode) - len(@SEPARATOR) )
  9. FROM
  10. __M_Contacts V1,
  11. __M_Matters V2
  12. WHERE 1=1
  13. AND V2.Final_ClientContact_Id = V1.Id
  14. AND CharIndex(V1.Final_ReferenceCode + @SEPARATOR, V2.Final_ReferenceCode) = 1

  15. GO