We have users creating duplicate customer accounts. To help cut down on this, I have a stored procedure that uses soundex to warn the users before saving the record. However it is not evaluating like I want. I was able to add customers 3 times without the address line being taken into account.
Code:
ALTER PROCEDURE [dbo].[co_individual_dup_check_NEW]
@ind_first_name nvarchar(255),
@ind_last_name nvarchar(255),
@adr_line1 nvarchar (255),
@adr_state nvarchar(255),
@adr_city nvarchar(255),
@ad2_adr_line1 nvarchar (255),
@ad2__adr_state nvarchar(255),
@ad2__adr_city nvarchar(255),
@ind_cst_key av_key
AS
set nocount on
select ind_cst_key,
[Individual] = isnull(cxa.cxa_mailing_label_html, ind_full_name_cp)
from co_individual (nolock)
join co_customer (nolock) on cst_key = ind_cst_key
left join co_customer_x_address cxa (nolock) on cxa.cxa_key = cst_cxa_key
left join co_address adr (nolock) on adr.adr_key = cxa.cxa_adr_key
where --soundex(ind_first_name)=soundex(@ind_first_name)and
soundex(ind_last_name)=soundex( @ind_last_name)
and ( (adr.adr_line1 is null)--added to evaluate address line 1 3-27-08 CSH
or (adr.adr_line1 = @adr_line1)--added 3/27/08 CSH
or (adr.adr_line1 = @ad2_adr_line1) )--added 3-27-08 CSH
and ( (adr.adr_state is null and adr.adr_city is null )
or (adr.adr_state = @adr_state and adr.adr_city = @adr_city )
or (adr.adr_state = @ad2__adr_state and adr.adr_city = @ad2__adr_city) )
and (ind_cst_key is not null or ind_cst_key <> @ind_cst_key)
and @ind_cst_key is null
and cst_delete_flag=0