USP_EVENTCONFLICT_DELETEALLGROUP

Executes the "Event Conflict Group Delete" record operation.

Parameters

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

Definition

Copy


                    CREATE procedure dbo.USP_EVENTCONFLICT_DELETEALLGROUP
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier
                    ) as
                        set nocount on;

                        declare @PROGRAMID uniqueidentifier;
                        select 
                            @PROGRAMID=PROGRAMID 
                        from
                            dbo.EVENTCONFLICT
                        where 
                            ID=@ID;

                        declare @CONFLICTID uniqueidentifier;
                        declare @NUMRECORDS int;
                        select @NUMRECORDS=COUNT(ID) from dbo.EVENTCONFLICT where PROGRAMID=@PROGRAMID;

                        while @NUMRECORDS > 0
                        begin
                            select top 1 @CONFLICTID=ID from dbo.EVENTCONFLICT where PROGRAMID=@PROGRAMID

                            --delete the location/s first

                            declare @NUMROWS int;
                            select @NUMROWS=count(*) from dbo.PROGRAMEVENTLOCATION where EVENTCONFLICTID=@CONFLICTID;

                            while @NUMROWS >0 
                            begin
                                declare @LOCATIONID uniqueidentifier;
                                select TOP 1
                                    @LOCATIONID=ID 
                                from 
                                    dbo.PROGRAMEVENTLOCATION 
                                where
                                    EVENTCONFLICTID=@CONFLICTID;

                                exec USP_PROGRAMEVENTLOCATION_DELETEBYID_WITHCHANGEAGENTID @LOCATIONID, @CHANGEAGENTID;    

                                set @NUMROWS=@NUMROWS-1;
                            end

                            --use the sp from delete one record operation

                            exec dbo.USP_EVENTCONFLICT_DELETE @CONFLICTID, @CHANGEAGENTID;
                            set @NUMRECORDS=@NUMRECORDS-1
                        end



                        return 0;