--:SetVar Procedure "AUX:RaiseError"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:RaiseError' )
   drop procedure [AUX:RaiseError]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:29.24 (stamp of SQL-file generation). */
create procedure [AUX:RaiseError]
   @ProcedureName    nvarchar(max)  = null,
   @TechMessage      nvarchar(max),
   @InMainLanguage   nvarchar(max) = null
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# ERROR GENERATION (WITH SOME LOCALIZATION SUPPORT):
#
# === Usage: ===
# exec [AUX:RaiseError] <Procedure name or null>, <Technical error message>
# exec [AUX:RaiseError] <Procedure name or null>,
#                       <Message in default language>, <Message in main language>
#
==================================================================================================*/
begin begin try set xact_abort off; set ansi_nulls,ansi_null_dflt_on,quoted_identifier,arithabort,nocount on; set implicit_transactions off; declare @initial_tran_count_aux int, @is_local_tran_open_aux bit; select @initial_tran_count_aux=@@trancount, @is_local_tran_open_aux=0; end try begin catch throw; end catch; begin try
----------------------------------------------------------------------------------------------------

if @TechMessage is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:RaiseError'

----------------------------------------------------------------------------------------------------

declare @ErrorMessage nvarchar(max)
set @ErrorMessage = dbo.[AUX:TechLocalText]( @TechMessage, @InMainLanguage )
if @ProcedureName is not null
   set @ErrorMessage = @ErrorMessage + (char(13)+char(10)) + dbo.[AUX:TechLocalText](
      '(Stored procedure: ['+ISNULL(@ProcedureName,'')+'])',
      N'(Процедура: ['+ISNULL(@ProcedureName,'')+N'])' )
raiserror (@ErrorMessage,11,1)

----------------------------------------------------------------------------------------------------
if @is_local_tran_open_aux=1 raiserror ('Not closed local transaction was detected, previously opened by BEGIN_TRANSACTION_AUX macro.',11,1); end try begin catch if @is_local_tran_open_aux=1 and (@@trancount>@initial_tran_count_aux or xact_state()=-1) rollback transaction; set @is_local_tran_open_aux=0; throw; end catch; end
/*================================================================================================*/
GO
/*
exec [AUX:RaiseError] null, N'Странная ошибка.'
exec [AUX:RaiseError] null, 'Strange error has occured.', N'Странная ошибка.'
*/
/*
exec [AUX:RaiseError] 'XProc', N'Странная ошибка.'
exec [AUX:RaiseError] 'XProc', 'Strange error has occured.', N'Странная ошибка.'
*/
