Hi All,
I've been trying to write a 'record-matching' statement for our customer database. It is comparing the First Name, Middle Name and Last Name and scoring the potential matches. The first criteria is a match on the first three characters of the customer's last name. The SQL is below.
The problem is that it is timing out for certain customers, and not just those that have more of those initial 3-character matches. Does anyone see any glaring issues with the statement? I got the basic code from another programmer, so I may be overlooking something. Thanks!
SELECT CUSTOMER_ID,
FIRST_NAME as CUST_FIRST_NAME,
SCORE_FNAME = CASE
WHEN [FIRST_NAME] = '' THEN 0
WHEN FIRST_NAME = [FIRST_NAME] THEN 20
WHEN SOUNDEX(REPLACE(FIRST_NAME,' ','')) = SOUNDEX(REPLACE([FIRST_NAME],' ','')) THEN 15
WHEN FIRST_NAME LIKE LEFT([FIRST_NAME],3) + '%' THEN 10
ELSE -10
END,
MIDDLE_NAME AS CUST_MIDDLE_NAME,
SCORE_MNAME = CASE
WHEN [MIDDLE_NAME] = '' THEN 0
WHEN MIDDLE_NAME LIKE LEFT([MIDDLE_NAME],1) + '%' THEN 5
ELSE 0
END,
LAST_NAME AS CUST_LAST_NAME,
SCORE_LNAME = CASE
WHEN [LAST_NAME] = '' THEN 0
WHEN LAST_NAME = [LAST_NAME] THEN 25
WHEN SOUNDEX(REPLACE(LAST_NAME,' ','')) = SOUNDEX(REPLACE([LAST_NAME],' ','')) THEN 15
ELSE 0
END,
CITY AS CUST_CITY
FROM CUST_DATA
WHERE LAST_NAME LIKE LEFT([LAST_NAME],3) + '%'
AND CUSTOMER_ID is not null
I've been trying to write a 'record-matching' statement for our customer database. It is comparing the First Name, Middle Name and Last Name and scoring the potential matches. The first criteria is a match on the first three characters of the customer's last name. The SQL is below.
The problem is that it is timing out for certain customers, and not just those that have more of those initial 3-character matches. Does anyone see any glaring issues with the statement? I got the basic code from another programmer, so I may be overlooking something. Thanks!
SELECT CUSTOMER_ID,
FIRST_NAME as CUST_FIRST_NAME,
SCORE_FNAME = CASE
WHEN [FIRST_NAME] = '' THEN 0
WHEN FIRST_NAME = [FIRST_NAME] THEN 20
WHEN SOUNDEX(REPLACE(FIRST_NAME,' ','')) = SOUNDEX(REPLACE([FIRST_NAME],' ','')) THEN 15
WHEN FIRST_NAME LIKE LEFT([FIRST_NAME],3) + '%' THEN 10
ELSE -10
END,
MIDDLE_NAME AS CUST_MIDDLE_NAME,
SCORE_MNAME = CASE
WHEN [MIDDLE_NAME] = '' THEN 0
WHEN MIDDLE_NAME LIKE LEFT([MIDDLE_NAME],1) + '%' THEN 5
ELSE 0
END,
LAST_NAME AS CUST_LAST_NAME,
SCORE_LNAME = CASE
WHEN [LAST_NAME] = '' THEN 0
WHEN LAST_NAME = [LAST_NAME] THEN 25
WHEN SOUNDEX(REPLACE(LAST_NAME,' ','')) = SOUNDEX(REPLACE([LAST_NAME],' ','')) THEN 15
ELSE 0
END,
CITY AS CUST_CITY
FROM CUST_DATA
WHERE LAST_NAME LIKE LEFT([LAST_NAME],3) + '%'
AND CUSTOMER_ID is not null