USP_PROGRAMDOCUMENT_RAISEPRIORITY

Executes the "Program Document Raise 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_RAISEPRIORITY
                    (
                        @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 @SEQUENCEDECREASED integer
                        declare @PROGRAMID uniqueidentifier

                        select @SEQUENCEDECREASED = SEQUENCE - 1,
                        @PROGRAMID = PROGRAMID
                        from dbo.PROGRAMDOCUMENT
                        where ID = @ID

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

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

                        return 0;
                    end