SQL Spreadsheets: Manually Prioritizing Matters

SQL Spreadsheets: Manually Prioritizing Matters



  1. --The following SQL will generate a list of matters and allow their priorities to easily be specified.
  2. CREATE OR ALTER FUNCTION SafeSingleLine (
  3. @Input NVARCHAR(MAX)
  4. ) RETURNS NVARCHAR(MAX) AS BEGIN
  5. DECLARE @Ret NVARCHAR(MAX) = COALESCE(@Input, '')

  6. SET @RET = REPLACE(@RET, CHAR(13), ' ')
  7. SET @RET = REPLACE(@RET, CHAR(10), ' ')
  8. SET @RET = REPLACE(@RET, CHAR(9), ' ')
  9. SET @RET = REPLACE(@RET, '''', ' ')
  10. SET @RET = REPLACE(@RET, ',', ' ')

  11. WHILE(CHARINDEX('  ', @RET) != 0) BEGIN
  12. SET @RET = REPLACE(@RET, '  ', ' ')
  13. END

  14. SET @Ret = TRIM(@RET)

  15. RETURN @RET
  16. END
  17. GO

  18. SELECT
  19.     V1.Batch_Group as 'Original Priority',
  20.     '' as 'New Priority',
  21.     V1.Id, 
  22.     dbo.SafeSingleLine(V2.Final_FullName) as 'Final_FullName',
  23.     dbo.SafeSingleLine(V1.Final_ReferenceCode) as 'Final_ReferenceCode', 
  24.     dbo.SafeSingleLine(V1.Final_Subject) as 'Final_Subject', 
  25.     dbo.SafeSingleLine(V1.Final_Description) as 'Final_Description',
  26.     V1.Final_Status,
  27.     Script = CONCAT(''
  28.       --IF cell A### = "Y"
  29.       , '=IF(INDIRECT("B"&ROW()) <> "",'
  30.   , '"'
  31.   , ' UPDATE'
  32.   , '   __M_Matters'
  33.   , ' SET'
  34.   , '   Batch_Group = '
  35.       , '     ''" & '
  36.   , '       INDIRECT("B"&ROW()) '
  37.   , '     & "'''
  38.   , ' WHERE 1=1'
  39.   , '   AND Id = '
  40.   , '     ''" & '
  41.   , '       INDIRECT("C"&ROW()) '
  42.   , '     & "'''
  43.   , '"'
  44.   --/THEN
  45.       , ', '
  46.   --ELSE
  47.   , '"'
  48.   , ' '
  49.   , '"'
  50.   --/ELSE
  51.       , ')'
  52.   )
  53. FROM
  54.     __M_Matters V1
  55. LEFT JOIN
  56.     __M_Contacts V2 ON V2.Id = V1.Final_ClientContact_Id
  57. ORDER BY
  58.     V1.Final_ReferenceCode
    • Related Articles

    • SQL Spreadsheets: Cherry Picking Matters

      The following SQL command will generate a spreadsheet that can be used to cherry-pick specific matters. CREATE OR ALTER FUNCTION SafeSingleLine ( @Input NVARCHAR(MAX) ) RETURNS NVARCHAR(MAX) AS BEGIN DECLARE @Ret NVARCHAR(MAX) = COALESCE(@Input, '') ...
    • SQL Spreadsheets: Reassigning Practice Areas

      Sometimes users want to reassign practice areas as part of the data restore into a new system. The following process makes it easy. Generate the SQL Spreadsheet Run the following command then copy the results and the headers into a Google Doc. ...
    • SQL Spreadsheets: Cherry-Picking Records

      As a general rule, we recommend that SQL scripts be used to mass-select/prune records; however, sometimes that is not possible. In these cases, we recommend having a member of the law firm complete a Google spreadsheet that clearly indicates what ...
    • 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', ...
    • SQL Spreadsheets: User Mappings

      The following SQL script will generate a Google Spreadsheet that will allow users to override email addresses. This is extremely helpful when merging old user accounts together. SELECT V1.Id, V1.Final_FullName as 'Old User (FullName)', ...