USP_CURRENCYEXCHANGERATE_DELETE

Executes the "Currency Exchange Rate: 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_CURRENCYEXCHANGERATE_DELETE
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier
                    ) as
                        set nocount on;

                        begin try
                            begin try
                                exec USP_CURRENCYEXCHANGERATE_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID;
                            end try
                            begin catch
                                declare @ERRORNUMBER int;
                                declare @ERRORMESSAGE nvarchar(1000);

                                set @ERRORNUMBER = ERROR_NUMBER();
                                set @ERRORMESSAGE = ERROR_MESSAGE();

                                if @ERRORNUMBER = 547
                                begin
                                    declare @CURRENCYEXCHANGERATEOBJECTID int;
                                    declare @CURRENCYEXCHANGERATEIDCOLUMNID int;
                                    set @CURRENCYEXCHANGERATEOBJECTID = OBJECT_ID('dbo.CURRENCYEXCHANGERATE');
                                    select @CURRENCYEXCHANGERATEIDCOLUMNID = sys.columns.column_id from sys.columns where sys.columns.object_id = @CURRENCYEXCHANGERATEOBJECTID and sys.columns.name = 'ID';

                                    if exists
                                    (
                                        select
                                            sys.foreign_keys.name
                                        from
                                            sys.foreign_keys
                                            inner join sys.foreign_key_columns on sys.foreign_keys.object_id = sys.foreign_key_columns.constraint_object_id
                                        where
                                            sys.foreign_key_columns.referenced_object_id = @CURRENCYEXCHANGERATEOBJECTID
                                            and sys.foreign_key_columns.referenced_column_id = @CURRENCYEXCHANGERATEIDCOLUMNID
                                            and @ERRORMESSAGE like '%' + replace(sys.foreign_keys.name, '_', '\_') + '%' escape '\'
                                    )
                                    begin
                                        declare @GENERALERRORMESSAGE nvarchar(max);
                                        set @GENERALERRORMESSAGE = 'BB_ERR_CURRENCYEXCHANGERATEINUSE : This exchange rate is being used by other records in the system and cannot be deleted. ' + @ERRORMESSAGE;
                                        raiserror(@GENERALERRORMESSAGE, 13, 1);
                                    end
                                end
                            end catch

                        end try

                        begin catch
                            exec dbo.USP_RAISE_ERROR;
                            return 1;
                        end catch

                        return 0;