USP_CURRENCY_DELETE

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

                        begin try

                            begin try

                                exec dbo.USP_CURRENCY_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 @CURRENCYOBJECTID int;
                                    declare @CURRENCYIDCOLUMNID int;
                                    set @CURRENCYOBJECTID = OBJECT_ID('dbo.CURRENCY');
                                    select @CURRENCYIDCOLUMNID = sys.columns.column_id from sys.columns where sys.columns.object_id = @CURRENCYOBJECTID 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 = @CURRENCYOBJECTID
                                            and sys.foreign_key_columns.referenced_column_id = @CURRENCYIDCOLUMNID
                                            and @ERRORMESSAGE like '%' + replace(sys.foreign_keys.name, '_', '\_') + '%' escape '\'
                                    )
                                    begin
                                        declare @GENERALERRORMESSAGE nvarchar(max);
                                        set @GENERALERRORMESSAGE = 'BB_ERR_CURRENCYINUSE : This currency 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;