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
Convert Users into Contacts
--Create contacts out of our users INSERT INTO __M_Contacts (Id, Final_Kind, Final_FirstName, Final_MiddleName, Final_LastName) SELECT CONCAT('__M_Users --- ', Id), 'Person', Final_FirstName, Final_MiddleName, Final_LastName FROM __M_Users
Synthesize Missing Client Contacts for Matters
This script below will create dummy contacts where the Matter is assigned to a contact that no longer exists. --Some of the Matters are linked to contacts that no longer exist. --This will create dummy contacts from the missing links. INSERT INTO ...
Other: Global SQL Search
The following query will create a stored procedure named SearchAllTables which will let you search all tables in the database for a value. It can be used the following ways: --Search for a column that exactly contains 'Test': exec SearchAllTables ...
Create Contact Categories from Matter Participants
--The following script will create Contact Categories from the roles --that Contacts are linked to on Matters and then assign the contacts to those categories. GO INSERT INTO __M_Contacts_Categories ( Id, Final_Subject ) SELECT DISTINCT ...
Create an "Employer" Contact from a Custom Field.
In some systems, contacts do not have an Employer relation and only have a text field that represents the employer. This script will help when moving firms into platforms that allow an actual contact to be specified for the employer. --Create Company ...