USP_SEARCHLISTREPLACEMENT_CREATE

Defines a replacement for an existing search list

Parameters

Parameter Parameter Type Mode Description
@SEARCHLISTID uniqueidentifier IN
@REPLACEMENTSEARCHLISTID uniqueidentifier IN
@CHANGEAGENTID uniqueidentifier IN

Definition

Copy


create procedure dbo.USP_SEARCHLISTREPLACEMENT_CREATE
(
    @SEARCHLISTID uniqueidentifier,
    @REPLACEMENTSEARCHLISTID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier = null
)
as

set nocount on;

--the pk on this table is a searchlist ID so it is possible that settings have been defined but not a replacement

-- if a row exists with a replacement, let the pk constraint raise the error

declare @existingID uniqueidentifier
select @existingID = ID from dbo.SEARCHLISTSETTINGS where ID = @SEARCHLISTID and REPLACEMENTSEARCHLISTID is null;

if @CHANGEAGENTID is null  
    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

declare @CURRENTDATE datetime
set @CURRENTDATE = getdate()

begin try

    if  @existingID is null
        insert into dbo.SEARCHLISTSETTINGS (ID, REPLACEMENTSEARCHLISTID, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
            values (@SEARCHLISTID, @REPLACEMENTSEARCHLISTID, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE);

    else
        update dbo.SEARCHLISTSETTINGS
        set    REPLACEMENTSEARCHLISTID = @REPLACEMENTSEARCHLISTID,
            CHANGEDBYID = @CHANGEAGENTID,
            DATECHANGED = @CURRENTDATE
        where ID = @existingID

end try

begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0