USP_DATAFORMTEMPLATE_EDIT_PDACCOUNTSEGMENTMAP2

The save procedure used by the edit dataform template "Account Segment Map Edit Form 2".

Parameters

Parameter Parameter Type Mode Description
@ID nvarchar(72) IN The input ID parameter indicating the ID of the record being edited.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@PDACCOUNTSTRUCTUREID nvarchar(36) IN Structure id
@LONGDESCRIPTIONID nvarchar(36) IN Long description id
@PDACCOUNTSEGMENTVALUEID nvarchar(36) IN Segment value

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_PDACCOUNTSEGMENTMAP2 (
    @ID nvarchar(72),
    @CHANGEAGENTID uniqueidentifier = null,
    @PDACCOUNTSTRUCTUREID nvarchar(36),
    @LONGDESCRIPTIONID nvarchar(36),
    @PDACCOUNTSEGMENTVALUEID nvarchar(36)
)
as


    set nocount on;

    declare @STRUCTUREID uniqueidentifier;
    declare @DESCRIPTIONID nvarchar(36)


    set    @STRUCTUREID = cast(substring(@ID,1,36) as uniqueidentifier)
    set @DESCRIPTIONID = substring(@ID,37,72)

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

    declare @CURRENTDATE datetime
    set @CURRENTDATE = getdate()

    begin try
        merge dbo.PDACCOUNTSEGMENTMAPPING as Target
        using (select     
        @ID as ID,
        @CHANGEAGENTID as CHANGEAGENTID,
        @STRUCTUREID as PDACCOUNTSTRUCTUREID,
        @DESCRIPTIONID as LONGDESCRIPTIONID,    
        @PDACCOUNTSEGMENTVALUEID as PDACCOUNTSEGMENTVALUEID,
        @CURRENTDATE as CURRENTDATE)
        as Source
        on (Target.LongDescriptionID = Source.LongDescriptionID and Target.PDACCOUNTSTRUCTUREID = Source.PDACCOUNTSTRUCTUREID)
        when matched then
            update set Target.PDACCOUNTSEGMENTVALUEID = Source.PDACCOUNTSEGMENTVALUEID,
                Target.CHANGEDBYID = Source.CHANGEAGENTID,
                Target.DATECHANGED = Source.CURRENTDATE
        when not matched by Target then
            insert (PDACCOUNTSTRUCTUREID,LONGDESCRIPTIONID,PDACCOUNTSEGMENTVALUEID,ISDEFAULT,ADDEDBYID,CHANGEDBYID,DATEADDED,DATECHANGED)
            values (Source.PDACCOUNTSTRUCTUREID, Source.LONGDESCRIPTIONID, Source.PDACCOUNTSEGMENTVALUEID,0, Source.CHANGEAGENTID, Source.CHANGEAGENTID, Source.CURRENTDATE, Source.CURRENTDATE);
    end try
    begin catch
        exec dbo.USP_RAISE_ERROR
        return 1
    end catch

return 0;