USP_POPULATESEARCHCONSTITUENTEXCLUDE
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@MINRECORDCOUNT | smallint | IN |
Definition
Copy
create procedure dbo.USP_POPULATESEARCHCONSTITUENTEXCLUDE
(@MINRECORDCOUNT smallint = 1000)
as
begin
truncate table dbo.SEARCHCONSTITUENTEXCLUDE
declare @CID uniqueidentifier
exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CID output
-- Add records to SEARCHCONSTITUENTEXCLUDE table to prevent long-running searches for common names like Smith.
-- Searches for these names without addresses could return thousands of records which is not useful anyway.
insert into dbo.SEARCHCONSTITUENTEXCLUDE (KEYNAME,FIRSTNAME3,ADDEDBYID,CHANGEDBYID)
select KEYNAME,FIRSTNAME3,@CID,@CID
from dbo.SEARCHCONSTITUENT
where POSTCODE=''
group by KEYNAME,FIRSTNAME3 having count(*) > @MINRECORDCOUNT
union
select KEYNAME,FIRSTNAME3,@CID,@CID
from dbo.SEARCHCONSTITUENT s1
where POSTCODE<>''
and not exists(select 'x' from dbo.SEARCHCONSTITUENT s2 where s2.KEYNAME=s1.KEYNAME and s2.FIRSTNAME3=s1.FIRSTNAME3 and s2.POSTCODE='')
group by KEYNAME,FIRSTNAME3 having count(*) > @MINRECORDCOUNT
end