:SetVar Procedure "AUX:RaiseIncorrectProcedureCall"
:r $(DropProcedureScript_AUX)
create procedure [$(Procedure)]
   @ProcedureName    $(dt_String_AUX),
   @CauseMessage     $(dt_Message_AUX) = null,
   @InMainLanguage   $(dt_Message_AUX) = null
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# ERROR GENERATION OF INCORRECT CALL OF STORED PROCEDURE:
#
# === Usage: ===
# exec [AUX:RaiseIncorrectProcedureCall] <Procedure name>, <Cause message>
# exec [AUX:RaiseIncorrectProcedureCall] <Procedure name>,
#                                        <Message in default language>, <Message in main language>
#
==================================================================================================*/
$(BEGIN_AUX)
----------------------------------------------------------------------------------------------------

declare @ErrorMessage $(dt_String_AUX)
set @ErrorMessage = dbo.[AUX:TechLocalText](
   'Incorrect call of ['+ISNULL(@ProcedureName,'')+'] stored procedure.',
   N'Некорректный вызов процедуры ['+ISNULL(@ProcedureName,'')+N'].' )
if @CauseMessage is not null
   set @ErrorMessage = @ErrorMessage + $(NL_AUX) + dbo.[AUX:TechLocalText](
      @CauseMessage, @InMainLanguage )
raiserror (@ErrorMessage,11,1)

----------------------------------------------------------------------------------------------------
$(END_AUX)
/*================================================================================================*/
GO
/*
exec [AUX:RaiseIncorrectProcedureCall] 'XProc'
exec [AUX:RaiseIncorrectProcedureCall] 'XProc', N'Несовместимые значения параметров.'
exec [AUX:RaiseIncorrectProcedureCall] 'XProc', 'Incompatible parameters.', N'Несовместимые значения параметров.'
*/
