USP_COUNTRYADDRESSFORMAT_DELETE

Executes the "Country Address Format: 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_COUNTRYADDRESSFORMAT_DELETE
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier
                    )
                    as begin

                        declare @FUNCTIONID as uniqueidentifier;
                        declare @FUNCTIONNAME as nvarchar(200);

                        select 
                            @FUNCTIONID = SQLFUNCTIONCATALOG.ID, 
                            @FUNCTIONNAME = COUNTRYADDRESSFORMAT.FORMATSQLFUNCTION
                        from dbo.COUNTRYADDRESSFORMAT
                            inner join dbo.SQLFUNCTIONCATALOG on SQLFUNCTIONCATALOG.FUNCTIONNAME = COUNTRYADDRESSFORMAT.FORMATSQLFUNCTION
                        where COUNTRYADDRESSFORMAT.ID = @ID;

                        exec dbo.USP_COUNTRYADDRESSFORMAT_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID;

                        --Remove the format's SQL function and spec.

                        exec dbo.USP_SQLFUNCTIONCATALOG_DELETEBYID_WITHCHANGEAGENTID @FUNCTIONID, @CHANGEAGENTID;

                        declare @SQL nvarchar(300) = 'drop function dbo.'+@FUNCTIONNAME+';';
                        exec sp_executesql @SQL

                        return 0;
                    end