USP_PROGRAMDOCUMENT_LOWERPRIORITY

Executes the "Program Document Lower Priority Record Operation" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being updated.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the update.

Definition

Copy


                    create procedure dbo.USP_PROGRAMDOCUMENT_LOWERPRIORITY
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier
                    )
                    as
                    begin
                        set nocount on;

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

                        declare @CURRENTDATE datetime
                        set @CURRENTDATE = getdate()

                        declare @SEQUENCEINCREASED integer
                        declare @PROGRAMID uniqueidentifier

                        select @SEQUENCEINCREASED = SEQUENCE + 1,
                        @PROGRAMID = PROGRAMID
                        from dbo.PROGRAMDOCUMENT
                        where ID = @ID

                        if exists
                        (
                            select 1
                            from dbo.PROGRAMDOCUMENT
                            where PROGRAMID = @PROGRAMID and @SEQUENCEINCREASED = SEQUENCE
                        )
                        begin
                            update
                                dbo.PROGRAMDOCUMENT
                            set
                                SEQUENCE = @SEQUENCEINCREASED -1,
                                CHANGEDBYID = @CHANGEAGENTID,
                                DATECHANGED = @CURRENTDATE
                            where PROGRAMID = @PROGRAMID and SEQUENCE = @SEQUENCEINCREASED

                            update
                                dbo.PROGRAMDOCUMENT
                            set
                                SEQUENCE = @SEQUENCEINCREASED,
                                CHANGEDBYID = @CHANGEAGENTID,
                                DATECHANGED = @CURRENTDATE
                            where ID = @ID
                        end

                        return 0;
                    end