SQL Spreadsheets: Manually Prioritizing Matters
- --The following SQL will generate a list of matters and allow their priorities to easily be specified.
- CREATE OR ALTER FUNCTION SafeSingleLine (
- @Input NVARCHAR(MAX)
- ) RETURNS NVARCHAR(MAX) AS BEGIN
- DECLARE @Ret NVARCHAR(MAX) = COALESCE(@Input, '')
- SET @RET = REPLACE(@RET, CHAR(13), ' ')
- SET @RET = REPLACE(@RET, CHAR(10), ' ')
- SET @RET = REPLACE(@RET, CHAR(9), ' ')
- SET @RET = REPLACE(@RET, '''', ' ')
- SET @RET = REPLACE(@RET, ',', ' ')
- WHILE(CHARINDEX(' ', @RET) != 0) BEGIN
- SET @RET = REPLACE(@RET, ' ', ' ')
- END
- SET @Ret = TRIM(@RET)
- RETURN @RET
- END
- GO
- SELECT
- V1.Batch_Group as 'Original Priority',
- '' as 'New Priority',
- V1.Id,
- dbo.SafeSingleLine(V2.Final_FullName) as 'Final_FullName',
- dbo.SafeSingleLine(V1.Final_ReferenceCode) as 'Final_ReferenceCode',
- dbo.SafeSingleLine(V1.Final_Subject) as 'Final_Subject',
- dbo.SafeSingleLine(V1.Final_Description) as 'Final_Description',
- V1.Final_Status,
- Script = CONCAT(''
- --IF cell A### = "Y"
- , '=IF(INDIRECT("B"&ROW()) <> "",'
- , '"'
- , ' UPDATE'
- , ' __M_Matters'
- , ' SET'
- , ' Batch_Group = '
- , ' ''" & '
- , ' INDIRECT("B"&ROW()) '
- , ' & "'''
- , ' WHERE 1=1'
- , ' AND Id = '
- , ' ''" & '
- , ' INDIRECT("C"&ROW()) '
- , ' & "'''
- , '"'
- --/THEN
- , ', '
- --ELSE
- , '"'
- , ' '
- , '"'
- --/ELSE
- , ')'
- )
- FROM
- __M_Matters V1
- LEFT JOIN
- __M_Contacts V2 ON V2.Id = V1.Final_ClientContact_Id
- ORDER BY
- 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)', ...