SQL Spreadsheets: Cherry Picking Contacts
The following SQL command will generate a spreadsheet that can be used to cherry-pick specific contacts.
- 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
- '' as 'Keep? (Y)',
- V1.Id,
- dbo.SafeSingleLine(V1.Final_ReferenceCode) as 'Final_ReferenceCode',
- dbo.SafeSingleLine(V1.Final_FullName) as 'Final_FullName',
- V1.Final_Status,
- Script = CONCAT(''
- --IF cell A### = "Y"
- , '=IF(INDIRECT("A"&ROW()) = "Y",'
- , '"'
- , ' UPDATE'
- , ' __M_Contacts'
- , ' SET'
- , ' Final_Status = Original_Status '
- , ' WHERE 1=1'
- , ' AND Id = '
- , ' ''" & '
- , ' INDIRECT("B"&ROW()) '
- , ' & "'''
- , '"'
- --/THEN
- , ', '
- --ELSE
- , '"'
- , ' '
- , '"'
- --/ELSE
- , ')'
- )
- FROM
- __M_Contacts V1
- ORDER BY
- V1.Final_ReferenceCode, V1.Final_FullName
Related Articles
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: 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: Cherry-Picking Custom Fields
The following SQL command will generate a Google Sheet that users can use to cherry-pick custom field definitions. SELECT '' as 'Keep? (Y)', V1.Id, V1.Final_Parent_Type, V1.Final_Kind, V1.Final_Subject, V1.Final_Description, V1.Final_Status, ...
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: 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, '') ...