Sometimes users want to reassign practice areas as part of the data restore into a new system. The following process makes it easy.
Run the following command then copy the results and the headers into a Google Doc.
- DECLARE @CRLF NVARCHAR(MAX) = CHAR(13) + CHAR(10);
- SELECT
- '' as 'New Practice Area',
- V1.Id,
- V3.Final_Subject as 'Original Practice Area',
- V2.Final_FullName,
- V1.Final_ReferenceCode,
- V1.Final_Subject,
- REPLACE(V1.Final_Description, @CRLF, '') as 'Final_Description',
- V1.Final_Status,
- Script =
- --IF cell A### = "Y"
- '=IF(INDIRECT("A"&ROW()) <> ""'
- --THEN: Generate the script using the ID in cell B###.
- + ', "Update __M_Matters SET Final_PracticeArea_Id = ''" & INDIRECT("A"&ROW()) & "'' WHERE Id = ''" & INDIRECT("B"&ROW()) & "''"'
- --ELSE: Blank script
- + ', ""'
- + ')'
- FROM
- __M_Matters V1
- LEFT JOIN
- __M_Contacts V2 ON V2.Id = V1.Final_ClientContact_Id
- LEFT JOIN
- __M_Matters_PracticeAreas V3 ON V3.Id = V1.Final_PracticeArea_Id
- ORDER BY
- V1.Final_ReferenceCode
After the client fills in the spreadsheet, run the generated SQL and then this command:
- --Link matters to practice areas that already exist
- UPDATE
- __M_Matters
- SET
- Final_PracticeArea_Id = V2.Id
- FROM
- __M_Matters V1,
- __M_Matters_PracticeAreas V2
- WHERE
- V1.Final_PracticeArea_Id = V2.Final_Subject
Then run this command to create any missing practice areas.