/*==================================================================================================
#
# DELETION OF ALL PROCEDURES OF SQLAUX-LIBRARY:
#
==================================================================================================*/
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
----------------------------------------------------------------------------------------------------

declare @PROCEDURE_LIST table ([Name] sysname primary key)
insert @PROCEDURE_LIST
   select [name] from [sysobjects] (nolock)
   where [type]='P' and [name] like 'AUX:%'

----------------------------------------------------------------------------------------------------
begin if @is_local_tran_open_aux=1 raiserror ('Local transaction nesting is forbidden. (Macro: BEGIN_TRANSACTION_AUX)',11,1); begin transaction; set @is_local_tran_open_aux=1; end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
while 0=0
begin
   declare @ProcedureName sysname
   select @ProcedureName=MIN([Name]) from @PROCEDURE_LIST
   if @ProcedureName is null BREAK

   exec( 'drop procedure ['+@ProcedureName+']' )

   delete @PROCEDURE_LIST where [Name] = @ProcedureName
end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
begin if @is_local_tran_open_aux=0 raiserror ('Open local transaction is absent. (Macro: COMMIT_TRANSACTION_AUX)',11,1); commit transaction; set @is_local_tran_open_aux=0; end
----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:RaiseIncorrectProcedureCall"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:RaiseIncorrectProcedureCall' )
   drop procedure [AUX:RaiseIncorrectProcedureCall]
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:RaiseIncorrectProcedureCall]
   @ProcedureName    nvarchar(max),
   @CauseMessage     nvarchar(max) = null,
   @InMainLanguage   nvarchar(max) = 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 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
----------------------------------------------------------------------------------------------------

declare @ErrorMessage nvarchar(max)
set @ErrorMessage = dbo.[AUX:TechLocalText](
   'Incorrect call of ['+ISNULL(@ProcedureName,'')+'] stored procedure.',
   N'Некорректный вызов процедуры ['+ISNULL(@ProcedureName,'')+N'].' )
if @CauseMessage is not null
   set @ErrorMessage = @ErrorMessage + (char(13)+char(10)) + dbo.[AUX:TechLocalText](
      @CauseMessage, @InMainLanguage )
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:RaiseIncorrectProcedureCall] 'XProc'
exec [AUX:RaiseIncorrectProcedureCall] 'XProc', N'Несовместимые значения параметров.'
exec [AUX:RaiseIncorrectProcedureCall] 'XProc', 'Incompatible parameters.', N'Несовместимые значения параметров.'
*/
--: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'Странная ошибка.'
*/
--:SetVar Procedure "AUX:InExternalTransaction.Verify"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:InExternalTransaction.Verify' )
   drop procedure [AUX:InExternalTransaction.Verify]
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:InExternalTransaction.Verify] @ProcedureName nvarchar(max)
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CHECKING, THAT STORED PROCEDURE IS EXECUTING UNDER POSITIVE TRANSACTION COUNT (>0):
#
# On-fail behaviour —— exception with localized message
#
# === Usage: ===
# exec [AUX:InExternalTransaction.Verify] <Procedure name>
#
==================================================================================================*/
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 @ProcedureName is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:InExternalTransaction.Verify'

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

if @@TRANCOUNT > 0 return

declare @ErrorMessage nvarchar(max)
set @ErrorMessage = dbo.[AUX:TechLocalText](
   'Procedure ['+@ProcedureName+'] must wokr inside outer transaction.',
   N'Процедура ['+@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:InExternalTransaction.Verify] 'XProc'
*/
--:SetVar Procedure "AUX:RaiseBlockedProcedure"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:RaiseBlockedProcedure' )
   drop procedure [AUX:RaiseBlockedProcedure]
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:RaiseBlockedProcedure] @ProcedureName nvarchar(max)
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# BLOCKING OF STORED PROCEDURE EXECUTION:
#
# === Usage: ===
# exec [AUX:RaiseBlockedProcedure] <Procedure name>
#
==================================================================================================*/
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 @ProcedureName is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:RaiseBlockedProcedure'

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

declare @ErrorMessage nvarchar(max)
set @ErrorMessage = dbo.[AUX:TechLocalText](
   'Procedure ['+@ProcedureName+'] is temporary blocked.',
   N'Процедура ['+@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:RaiseBlockedProcedure] 'XProc'
*/
--:SetVar Procedure "AUX:RaiseBlockedScript"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:RaiseBlockedScript' )
   drop procedure [AUX:RaiseBlockedScript]
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:RaiseBlockedScript]
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# GENERATION OF BLOCKED SCRIPT ERROR:
#
# === Usage: ===
# exec [AUX:RaiseBlockedScript]
#
==================================================================================================*/
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
----------------------------------------------------------------------------------------------------

exec [AUX:RaiseError] null,
   'Execution of the script is locked.',
   N'Выполнение скрипта заблокировано.'

----------------------------------------------------------------------------------------------------
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:RaiseBlockedScript]
*/
--:SetVar Procedure "AUX:RaiseDebugException"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:RaiseDebugException' )
   drop procedure [AUX:RaiseDebugException]
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:RaiseDebugException] @ProcedureName nvarchar(max)=null
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# GENERATION OF DEBUG EXCEPTION ERROR IN STORED PROCEDURE OR SCRIPT:
#
# === Usage: ===
# exec [AUX:RaiseDebugException] <Procedure name>
# exec [AUX:RaiseDebugException]
#
==================================================================================================*/
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
----------------------------------------------------------------------------------------------------

declare @ErrorMessage nvarchar(max)
set @ErrorMessage =
case
   when @ProcedureName is not null then
      dbo.[AUX:TechLocalText](
         'Artificial debug exception in ['+@ProcedureName+'] procedure.',
         N'Искусственное исключение отладки в процедуре ['+@ProcedureName+N'].' )
   else
      dbo.[AUX:TechLocalText](
         'Artificial debug exception has occured.',
         N'Искусственное исключение отладки.' )
end
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:RaiseDebugException] 'XProc'
exec [AUX:RaiseDebugException]
*/
--:SetVar Procedure "AUX:RaiseNotImplemented"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:RaiseNotImplemented' )
   drop procedure [AUX:RaiseNotImplemented]
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:RaiseNotImplemented] @ProcedureName nvarchar(max)=null
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# GENERATION OF NOT IMPLEMENTED CODE ERROR IN STORED PROCEDURE OR SCRIPT:
#
# === Usage: ===
# exec [AUX:RaiseNotImplemented]
# exec [AUX:RaiseNotImplemented] <Procedure name>
#
==================================================================================================*/
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
----------------------------------------------------------------------------------------------------

declare @ErrorMessage nvarchar(max)
set @ErrorMessage =
case
   when @ProcedureName is not null then
      dbo.[AUX:TechLocalText](
         'Not implemented code exception in ['+@ProcedureName+'] procedure.',
         N'Исключение нереализованного кода в процедуре ['+@ProcedureName+N'].' )
   else
      dbo.[AUX:TechLocalText](
         'Not implemented code exception has occured.',
         N'Исключение нереализованного кода.' )
end
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:RaiseNotImplemented] 'XProc'
exec [AUX:RaiseNotImplemented]
*/
--:SetVar Procedure "AUX:RaiseNullParameter"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:RaiseNullParameter' )
   drop procedure [AUX:RaiseNullParameter]
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:RaiseNullParameter] @ProcedureName nvarchar(max),
                                @ParameterName nvarchar(max)
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# GENERATION OF NULL-PARAMETER ERROR OF STORED PROCEDURE:
#
# === Usage: ===
# exec [AUX:RaiseNullParameter] <Procedure name>, <Parameter name>
#
==================================================================================================*/
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 @ProcedureName is null or
   @ParameterName is null or @ParameterName=''
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:RaiseNullParameter'

declare @ErrorMessage nvarchar(max)
set @ErrorMessage = dbo.[AUX:TechLocalText](
   'Incorrect call of ['+ISNULL(@ProcedureName,'')+'] stored procedure.'+(char(13)+char(10))+
   'Parameter '+@ParameterName+' must not be null.',
   N'Некорректный вызов процедуры ['+ISNULL(@ProcedureName,'')+N'].'+(char(13)+char(10))+
   N'Параметр '+@ParameterName+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:RaiseNullParameter] 'XProc', '@Value'
*/
--:SetVar Procedure "AUX:RaiseRollbackException"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:RaiseRollbackException' )
   drop procedure [AUX:RaiseRollbackException]
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:RaiseRollbackException] @ProcedureName nvarchar(max)=null
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# GENERATION OF ROLLBACK EXCEPTION IN STORED PROCEDURE OR SCRIPT (DEBUG ERROR):
#
# === Usage: ===
# exec [AUX:RaiseRollbackException] <Procedure name>
# exec [AUX:RaiseRollbackException]
#
==================================================================================================*/
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
----------------------------------------------------------------------------------------------------

declare @ErrorMessage nvarchar(max)
set @ErrorMessage =
case
   when @ProcedureName is not null then
      dbo.[AUX:TechLocalText](
         'Artificial debug exception in ['+@ProcedureName+'] procedure (rollback).',
         N'Искусственное исключение отладки в процедуре ['+@ProcedureName+N'] (откат).' )
   else
      dbo.[AUX:TechLocalText](
         'Artificial debug exception has occured (rollback).',
         N'Искусственное исключение отладки (откат).' )
end
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:RaiseRollbackException] 'XProc'
exec [AUX:RaiseRollbackException]
*/
--:SetVar Procedure "AUX:RaiseUnexpectedInternalError"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:RaiseUnexpectedInternalError' )
   drop procedure [AUX:RaiseUnexpectedInternalError]
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:RaiseUnexpectedInternalError]
   @ProcedureName    nvarchar(max) = null,
   @SituationMarker  uniqueidentifier = null
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# GENERATION OF UNEXPECTED INTERNAL ERROR IN STORED PROCEDURE OR SCRIPT:
#
# === Usage: ===
# exec [AUX:RaiseUnexpectedInternalError] <Procedure name>
# exec [AUX:RaiseUnexpectedInternalError] <Procedure name>, <Situation marker>
# exec [AUX:RaiseUnexpectedInternalError]
# exec [AUX:RaiseUnexpectedInternalError] null, <Situation marker>
#
==================================================================================================*/
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
----------------------------------------------------------------------------------------------------
declare @LanguageId int
set @LanguageId = dbo.[AUX:TechLanguage]()
if @LanguageId=0 goto IN_ENGLISH
if @LanguageId=21 goto IN_RUSSIAN
goto IN_ENGLISH
----------------------------------------------------------------------------------------------------
declare @ErrorMessage nvarchar(max)
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IN_ENGLISH:
if @ProcedureName is not null
   set @ErrorMessage = case when ISNULL(@ErrorMessage,'')<>'' then ISNULL(@ErrorMessage,'')+(char(13)+char(10)) else '' end +
      'Unexpected internal error in ['+@ProcedureName+'] procedure.'
else
   set @ErrorMessage = case when ISNULL(@ErrorMessage,'')<>'' then ISNULL(@ErrorMessage,'')+(char(13)+char(10)) else '' end +
      'Unexpected internal error.'
if @SituationMarker is not null
   set @ErrorMessage = case when ISNULL(@ErrorMessage,'')<>'' then ISNULL(@ErrorMessage,'')+(char(13)+char(10)) else '' end +
      'Situation marker: '+CONVERT( char(36), @SituationMarker )+'.'
raiserror (@ErrorMessage,11,1)
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IN_RUSSIAN:
if @ProcedureName is not null
   set @ErrorMessage = case when ISNULL(@ErrorMessage,'')<>'' then ISNULL(@ErrorMessage,'')+(char(13)+char(10)) else '' end +
      N'Непредвиденная внутренняя ошибка в процедуре ['+@ProcedureName+N'].'
else
   set @ErrorMessage = case when ISNULL(@ErrorMessage,'')<>'' then ISNULL(@ErrorMessage,'')+(char(13)+char(10)) else '' end +
      N'Непредвиденная внутренняя ошибка.'
if @SituationMarker is not null
   set @ErrorMessage = case when ISNULL(@ErrorMessage,'')<>'' then ISNULL(@ErrorMessage,'')+(char(13)+char(10)) else '' end +
      N'Маркер ситуации: '+CONVERT( char(36), @SituationMarker )+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:RaiseUnexpectedInternalError] 'XProc'
exec [AUX:RaiseUnexpectedInternalError] 'XProc', '11C7BA65-9075-4C9E-BB5A-FCAEDBE62F95'
exec [AUX:RaiseUnexpectedInternalError] null, 'F701CE8D-DD22-423D-9B78-206239E80D30'
exec [AUX:RaiseUnexpectedInternalError]
*/
--:SetVar Procedure "AUX:DropFunction"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:DropFunction' )
   drop procedure [AUX:DropFunction]
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:DropFunction] @FunctionName nvarchar(max)
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# FUNCTION DELETION ROUTINE (IF FUNCTION OBJECT EXISTS):
#
# === Usage: ===
# exec [AUX:DropFunction] <Function name>
#
==================================================================================================*/
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 @FunctionName is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:DropFunction'

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

if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=@FunctionName )
   exec( 'drop function ['+@FunctionName+']' )

----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:DropProcedure"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:DropProcedure' )
   drop procedure [AUX:DropProcedure]
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:DropProcedure] @ProcedureName nvarchar(max)
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# STORED PROCEDURE DELETION ROUTINE (IF PROCEDURE OBJECT EXISTS):
#
# === Usage: ===
# exec [AUX:DropProcedure] <Procedure name>
#
==================================================================================================*/
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 @ProcedureName is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:DropProcedure'

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

if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=@ProcedureName )
   exec( 'drop procedure ['+@ProcedureName+']' )

----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:DropTable"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:DropTable' )
   drop procedure [AUX:DropTable]
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:DropTable] @TableName nvarchar(max)
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# TABLE REMOVING ROUTINE (IF TABLE OBJECT EXISTS):
#
# === Usage: ===
# exec [AUX:DropTable] <Table name>
#
==================================================================================================*/
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 @TableName is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:DropTable'

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

if exists( select * from [sysobjects] (nolock) where [type]='U' and [name]=@TableName )
   exec( 'drop table ['+@TableName+']' )

----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:DropTrigger"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:DropTrigger' )
   drop procedure [AUX:DropTrigger]
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:DropTrigger] @TriggerName nvarchar(max)
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# TRIGGER DELETION ROUTINE (IF TRIGGER OBJECT EXISTS):
#
# === Usage: ===
# exec [AUX:DropTrigger] <Trigger name>
#
==================================================================================================*/
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 @TriggerName is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:DropTrigger'

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

if exists( select * from [sysobjects] (nolock) where [type]='TR' and [name]=@TriggerName )
   exec( 'drop trigger ['+@TriggerName+']' )

----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:DropType"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:DropType' )
   drop procedure [AUX:DropType]
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:DropType] @TypeName nvarchar(max)
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DATA TYPE DELETION ROUTINE (IF TYPE OBJECT EXISTS):
#
# === Usage: ===
# exec [AUX:DropType] <Type name>
#
==================================================================================================*/
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 @TypeName is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:DropType'

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

if exists( select * from [systypes] (nolock) where [name]=@TypeName )
   exec [sp_DropType] @TypeName

----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:DropView"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:DropView' )
   drop procedure [AUX:DropView]
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:DropView] @ViewName nvarchar(max)
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# TABLE VIEW DELETION ROUTINE (IF VIEW OBJECT EXISTS):
#
# === Usage: ===
# exec [AUX:DropView] <View name>
#
==================================================================================================*/
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 @ViewName is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:DropView'

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

if exists( select * from [sysobjects] (nolock) where [type]='V' and [name]=@ViewName )
   exec( 'drop view ['+@ViewName+']' )

----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:DropFunctions"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:DropFunctions' )
   drop procedure [AUX:DropFunctions]
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:DropFunctions] @NamePattern       nvarchar(max),
                                @ExceptionPattern  nvarchar(max) = null
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# FUNCTION SET DELETION ROUTINE (BY NAME PATTERN, OF EXISTING FUNCTION OBJECTS):
#
# === Usage: ===
# exec [AUX:DropFunctions] N'<Prefix token>:%'
# exec [AUX:DropFunctions] N'<Prefix token>::%'
# exec [AUX:DropFunctions] N'<Prefix token>:%', N'<Prefix token>::%'
# exec [AUX:DropFunctions] N'<Prefix token>\_%'
#
# ( Character “\” serves as “escape” for indication,
#   that “_” symbol is not used as placeholder. )
#
# *** CAUTION: ***
# USE THIS PROCEDURE WITH HIGH CAUTION
# TO AVOID UNINTENDED REMOVING OF FUNCTION OBJECTS!
#
==================================================================================================*/
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 @NamePattern is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:DropFunctions'

if CHARINDEX(' ',@NamePattern)>0 or
   @NamePattern='%' or SUBSTRING(@NamePattern,1,2)='%%'
   exec [AUX:RaiseError] 'AUX:DropFunctions',
      'Incorrect pattern for function name.',
      N'Некорректный шаблон имени функции.'

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

declare @FUNCTION_LIST table ([Name] sysname primary key)
insert @FUNCTION_LIST
   select [name] from [sysobjects] (nolock)
   where [type] in ('FN','TF') and [name] like @NamePattern escape '\' and
         ( @ExceptionPattern is null or [name] not like @ExceptionPattern escape '\' )

----------------------------------------------------------------------------------------------------
begin if @is_local_tran_open_aux=1 raiserror ('Local transaction nesting is forbidden. (Macro: BEGIN_TRANSACTION_AUX)',11,1); begin transaction; set @is_local_tran_open_aux=1; end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
while 0=0
begin
   declare @FunctionName sysname
   select @FunctionName = MIN([Name]) from @FUNCTION_LIST
   if @FunctionName is null BREAK

   exec( 'drop function ['+@FunctionName+']' )

   delete @FUNCTION_LIST where [Name] = @FunctionName
end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
begin if @is_local_tran_open_aux=0 raiserror ('Open local transaction is absent. (Macro: COMMIT_TRANSACTION_AUX)',11,1); commit transaction; set @is_local_tran_open_aux=0; end
----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:DropProcedures"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:DropProcedures' )
   drop procedure [AUX:DropProcedures]
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:DropProcedures] @NamePattern       nvarchar(max),
                                @ExceptionPattern  nvarchar(max) = null
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# STORED PROCEDURE SET DELETION ROUTINE (BY NAME PATTERN, OF EXISTING PROCEDURE OBJECTS):
#
# === Usage: ===
# exec [AUX:DropProcedures] N'<Prefix token>:%'
# exec [AUX:DropProcedures] N'<Prefix token>::%'
# exec [AUX:DropProcedures] N'<Prefix token>:%', N'<Prefix token>::%'
# exec [AUX:DropProcedures] N'<Prefix token>\_%'
#
# ( Character “\” serves as “escape” for indication,
#   that “_” symbol is not used as placeholder. )
#
# *** CAUTION: ***
# USE THIS PROCEDURE WITH HIGH CAUTION
# TO AVOID UNINTENDED REMOVING OF PROCEDURE OBJECTS!
#
==================================================================================================*/
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 @NamePattern is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:DropProcedures'

if CHARINDEX(' ',@NamePattern)>0 or
   @NamePattern='%' or SUBSTRING(@NamePattern,1,2)='%%'
   exec [AUX:RaiseError] 'AUX:DropProcedures',
      'Incorrect pattern for procedure name.',
      N'Некорректный шаблон имени процедуры.'

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

declare @PROCEDURE_LIST table ([Name] sysname primary key)
insert @PROCEDURE_LIST
   select [name] from [sysobjects] (nolock)
   where [type]='P' and [name] like @NamePattern escape '\' and
         ( @ExceptionPattern is null or [name] not like @ExceptionPattern escape '\' )

----------------------------------------------------------------------------------------------------
begin if @is_local_tran_open_aux=1 raiserror ('Local transaction nesting is forbidden. (Macro: BEGIN_TRANSACTION_AUX)',11,1); begin transaction; set @is_local_tran_open_aux=1; end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
while 0=0
begin
   declare @ProcedureName sysname
   select @ProcedureName = MIN([Name]) from @PROCEDURE_LIST
   if @ProcedureName is null BREAK

   exec( 'drop procedure ['+@ProcedureName+']' )

   delete @PROCEDURE_LIST where [Name] = @ProcedureName
end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
begin if @is_local_tran_open_aux=0 raiserror ('Open local transaction is absent. (Macro: COMMIT_TRANSACTION_AUX)',11,1); commit transaction; set @is_local_tran_open_aux=0; end
----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:DropTriggers"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:DropTriggers' )
   drop procedure [AUX:DropTriggers]
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:DropTriggers] @NamePattern       nvarchar(max),
                                @ExceptionPattern  nvarchar(max) = null
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# TRIGGER SET DELETION ROUTINE (BY NAME PATTERN, OF EXISTING TRIGGER OBJECTS):
#
# === Usage: ===
# exec [AUX:DropTriggers] N'<Prefix token>:%'
# exec [AUX:DropTriggers] N'<Prefix token>::%'
# exec [AUX:DropTriggers] N'<Prefix token>:%', N'<Prefix token>::%'
# exec [AUX:DropTriggers] N'<Prefix token>\_%'
#
# ( Character “\” serves as “escape” for indication,
#   that “_” symbol is not used as placeholder. )
#
# *** CAUTION: ***
# USE THIS PROCEDURE WITH HIGH CAUTION
# TO AVOID UNINTENDED REMOVING OF TRIGGER OBJECTS!
#
==================================================================================================*/
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 @NamePattern is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:DropTriggers'

if CHARINDEX(' ',@NamePattern)>0 or
   @NamePattern='%' or SUBSTRING(@NamePattern,1,2)='%%'
   exec [AUX:RaiseError] 'AUX:DropTriggers',
      'Incorrect pattern for trigger name.',
      N'Некорректный шаблон имени триггера.'

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

declare @TRIGGER_LIST table ([Name] sysname primary key)
insert @TRIGGER_LIST
   select [name] from [sysobjects] (nolock)
   where [type]='TR' and [name] like @NamePattern escape '\' and
         ( @ExceptionPattern is null or [name] not like @ExceptionPattern escape '\' )

----------------------------------------------------------------------------------------------------
begin if @is_local_tran_open_aux=1 raiserror ('Local transaction nesting is forbidden. (Macro: BEGIN_TRANSACTION_AUX)',11,1); begin transaction; set @is_local_tran_open_aux=1; end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
while 0=0
begin
   declare @TriggerName sysname
   select @TriggerName = MIN([Name]) from @TRIGGER_LIST
   if @TriggerName is null BREAK

   exec( 'drop trigger ['+@TriggerName+']' )

   delete @TRIGGER_LIST where [Name] = @TriggerName
end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
begin if @is_local_tran_open_aux=0 raiserror ('Open local transaction is absent. (Macro: COMMIT_TRANSACTION_AUX)',11,1); commit transaction; set @is_local_tran_open_aux=0; end
----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:DropTypes"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:DropTypes' )
   drop procedure [AUX:DropTypes]
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:DropTypes] @NamePattern       nvarchar(max),
                                @ExceptionPattern  nvarchar(max) = null
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DATA TYPE SET DELETION ROUTINE (BY NAME PATTERN, OF EXISTING TYPE OBJECTS):
#
# === Usage: ===
# exec [AUX:DropTypes] N'<Prefix token>:%'
# exec [AUX:DropTypes] N'<Prefix token>::%'
# exec [AUX:DropTypes] N'<Prefix token>:%', N'<Prefix token>::%'
# exec [AUX:DropTypes] N'<Prefix token>\_%'
#
# ( Character “\” serves as “escape” for indication,
#   that “_” symbol is not used as placeholder. )
#
# *** CAUTION: ***
# USE THIS PROCEDURE WITH HIGH CAUTION
# TO AVOID UNINTENDED REMOVING OF TYPE OBJECTS!
#
==================================================================================================*/
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 @NamePattern is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:DropTypes'

if CHARINDEX(' ',@NamePattern)>0 or
   @NamePattern='%' or SUBSTRING(@NamePattern,1,2)='%%'
   exec [AUX:RaiseError] 'AUX:DropTypes',
      'Incorrect pattern for data type name.',
      N'Некорректный шаблон имени типа данных.'

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

declare @TYPE_LIST table ([Name] sysname primary key)
insert @TYPE_LIST
   select [name] from [systypes] (nolock)
   where [name] like @NamePattern escape '\' and
         ( @ExceptionPattern is null or [name] not like @ExceptionPattern escape '\' )

----------------------------------------------------------------------------------------------------
begin if @is_local_tran_open_aux=1 raiserror ('Local transaction nesting is forbidden. (Macro: BEGIN_TRANSACTION_AUX)',11,1); begin transaction; set @is_local_tran_open_aux=1; end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
while 0=0
begin
   declare @TypeName sysname
   select @TypeName = MIN([Name]) from @TYPE_LIST
   if @TypeName is null BREAK

   exec [sp_DropType] @TypeName

   delete @TYPE_LIST where [Name] = @TypeName
end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
begin if @is_local_tran_open_aux=0 raiserror ('Open local transaction is absent. (Macro: COMMIT_TRANSACTION_AUX)',11,1); commit transaction; set @is_local_tran_open_aux=0; end
----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:DropViews"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:DropViews' )
   drop procedure [AUX:DropViews]
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:DropViews] @NamePattern       nvarchar(max),
                                @ExceptionPattern  nvarchar(max) = null
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# TABLE VIEW SET DELETION ROUTINE (BY NAME PATTERN, OF EXISTING VIEW OBJECTS):
#
# === Usage: ===
# exec [AUX:DropViews] N'<Prefix token>:%'
# exec [AUX:DropViews] N'<Prefix token>::%'
# exec [AUX:DropViews] N'<Prefix token>:%', N'<Prefix token>::%'
# exec [AUX:DropViews] N'<Prefix token>\_%'
#
# ( Character “\” serves as “escape” for indication,
#   that “_” symbol is not used as placeholder. )
#
# *** CAUTION: ***
# USE THIS PROCEDURE WITH HIGH CAUTION
# TO AVOID UNINTENDED REMOVING OF VIEW OBJECTS!
#
==================================================================================================*/
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 @NamePattern is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:DropViews'

if CHARINDEX(' ',@NamePattern)>0 or
   @NamePattern='%' or SUBSTRING(@NamePattern,1,2)='%%'
   exec [AUX:RaiseError] 'AUX:DropViews',
      'Incorrect pattern for view name.',
      N'Некорректный шаблон имени представления.'

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

declare @VIEW_LIST table ([Name] sysname primary key)
insert @VIEW_LIST
   select [name] from [sysobjects] (nolock)
   where [type]='V' and [name] like @NamePattern escape '\' and
         ( @ExceptionPattern is null or [name] not like @ExceptionPattern escape '\' )

----------------------------------------------------------------------------------------------------
begin if @is_local_tran_open_aux=1 raiserror ('Local transaction nesting is forbidden. (Macro: BEGIN_TRANSACTION_AUX)',11,1); begin transaction; set @is_local_tran_open_aux=1; end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
while 0=0
begin
   declare @ViewName sysname
   select @ViewName = MIN([Name]) from @VIEW_LIST
   if @ViewName is null BREAK

   exec( 'drop view ['+@ViewName+']' )

   delete @VIEW_LIST where [Name] = @ViewName
end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
begin if @is_local_tran_open_aux=0 raiserror ('Open local transaction is absent. (Macro: COMMIT_TRANSACTION_AUX)',11,1); commit transaction; set @is_local_tran_open_aux=0; end
----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:GrantExecOnProcedures"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:GrantExecOnProcedures' )
   drop procedure [AUX:GrantExecOnProcedures]
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:GrantExecOnProcedures]
   @ProcedureNamePattern   nvarchar(max),
   @UserOrGroupName        nvarchar(max)
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# EXECUTION RIGHT ASSIGNMENT — ON SET OF STORED PROCEDURES (BY NAME PATTERN, ON EXISTING OBJECTS):
#
# === Usage: ===
# exec [AUX:GrantExecOnProcedures] '<Prefix token>:%', <User name or user group name>
# exec [AUX:GrantExecOnProcedures] '<Prefix token>\_%', <User name or user group name>
#
# ( Character “\” serves as “escape” for indication,
#   that “_” symbol is not used as placeholder. )
#
# *** CAUTION: ***
# USE THIS PROCEDURE WITH HIGH CAUTION
# TO AVOID UNINTENDED EXECUTION RIGHT ASSIGNMENT!
#
==================================================================================================*/
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 @ProcedureNamePattern is null or @UserOrGroupName is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:GrantExecOnProcedures'

if CHARINDEX(' ',@ProcedureNamePattern)>0 or
   @ProcedureNamePattern='%' or SUBSTRING(@ProcedureNamePattern,1,2)='%%'
   exec [AUX:RaiseError] 'AUX:GrantExecOnProcedures',
      'Incorrect pattern for procedure name.',
      N'Некорректный шаблон имени процедуры.'

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

declare @PROCEDURE_LIST table ([Name] sysname primary key)
insert @PROCEDURE_LIST
   select [name] from [sysobjects] (nolock)
   where [type]='P' and [name] like @ProcedureNamePattern escape '\'

while 0=0
begin
   declare @ProcedureName sysname
   select @ProcedureName=MIN([Name]) from @PROCEDURE_LIST
   if @ProcedureName is null break

   exec( 'grant execute on ['+@ProcedureName+'] to ['+@UserOrGroupName+']' )

   delete @PROCEDURE_LIST where [Name] = @ProcedureName
end

----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:ListProcesses"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:ListProcesses' )
   drop procedure [AUX:ListProcesses]
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:ListProcesses] @DatabaseName nvarchar(max)='*'
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LISTING OF SQL PROCESSES (QUERIES):
#
# === Usage: ===
# exec [AUX:ListProcesses]                 -- all processes
# exec [AUX:ListProcesses] <Database name> -- processes in specified DB
# exec [AUX:ListProcesses] '.'             -- processes in current DB
# exec [AUX:ListProcesses] '*'             -- all processes
# exec [AUX:ListProcesses] null            -- processes without database context
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# === Result-set: ===
# [Is current]         bit       not null
# [Database name]      sysname   not null
# [SPID]               int       not null
# [Status]             sysname   not null
# [Command]            sysname   not null
# [CPU]                int       not null
# [Login name]         sysname   not null
# [Application name]   sysname   not null
# [Host name]          sysname   not null
# [Login time]         datetime2 not null
# [Last batch time]    datetime2 not null
# ___ Order: ___
# : [Status] = 'runnable' — to list beginning;
# : current @@SPID — to list beginning;
# : current DB — to list beginning;
# [Database name] (heavy null-s);
# [SPID]
==================================================================================================*/
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
----------------------------------------------------------------------------------------------------
declare @ErrorMessage nvarchar(max), @DatabaseId int
----------------------------------------------------------------------------------------------------

if @DatabaseName is not null
begin
   set @DatabaseName=RTRIM(@DatabaseName)
   if dbo.[AUX:StrLength](@DatabaseName)=0 or LTRIM(@DatabaseName)<>@DatabaseName
      exec [AUX:RaiseIncorrectProcedureCall] 'AUX:ListProcesses'
end

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

if @DatabaseName is not null and @DatabaseName<>'*'
   if @DatabaseName = '.'
      select @DatabaseId = db.[dbid]
      from [sysprocesses] p (nolock)
      join [sysdatabases] db (nolock)
           on p.[dbid] = db.[dbid] and p.[spid] = @@SPID
   else
   begin
      select @DatabaseId = [dbid] from [sysdatabases] (nolock) where [name] = @DatabaseName
      if @@rowcount=0
      begin
         set @ErrorMessage = dbo.[AUX:LocalizedText](
            'Database not found by name: “'+@DatabaseName+'”.',
            N'База данных по имени не найдена: “'+@DatabaseName+N'”.' )
         raiserror (@ErrorMessage,11,1)
      end
   end

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

select
   CONVERT( bit,
      case when p.[spid] = @@SPID
      then 1 else 0 end )  'Is current',
   ISNULL(db.[name],'')    'Database name',
   p.[spid]                'SPID',
   case p.[status]
      when 'runnable' then UPPER(p.[status])
      else LOWER(p.[status])
   end                     'Status',
   p.[cmd]                 'Command',
   p.[cpu]                 'CPU',
   p.[loginame]            'Login name',
   p.[program_name]        'Application name',
   p.[hostname]            'Host name',
   p.[login_time]          'Login time',
   p.[last_batch]          'Last batch time'
from
   [sysprocesses] p (nolock)
left join
   [sysdatabases] db (nolock)
   on p.[dbid] = db.[dbid]
where
   @DatabaseName = '*' or
   ( @DatabaseName is not null and db.[dbid] = @DatabaseId ) or
   ( @DatabaseName is     null and db.[dbid] is null  )
order by
   case
      when p.[status] = 'runnable'
      then 0 else 1
   end,
   case
      when p.[spid] = @@SPID
      then 0 else 1
   end,
   case
      when db.[dbid] is null
      then 1 else 0
   end,
   IIF( db.[name] is null, 1, 0 ),
   db.[name],
   p.[spid]

----------------------------------------------------------------------------------------------------
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:ListProcesses]
exec [AUX:ListProcesses] N'TEST'
exec [AUX:ListProcesses] '.'
exec [AUX:ListProcesses] '*'
exec [AUX:ListProcesses] null
*/
--:SetVar Procedure "AUX:RevokeExecOnProcedures"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:RevokeExecOnProcedures' )
   drop procedure [AUX:RevokeExecOnProcedures]
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:RevokeExecOnProcedures]
   @ProcedureNamePattern   nvarchar(max),
   @UserOrGroupName        nvarchar(max)
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# EXECUTION RIGHT REVOCATION — ON SET OF STORED PROCEDURES (BY NAME PATTERN, ON EXISTING OBJECTS):
#
# === Usage: ===
# exec [AUX:RevokeExecOnProcedures] '<Prefix token>:%', <User name or user group name>
# exec [AUX:RevokeExecOnProcedures] '<Prefix token>\_%', <User name or user group name>
#
# ( Character “\” serves as “escape” for indication,
#   that “_” symbol is not used as placeholder. )
#
# *** CAUTION: ***
# USE THIS PROCEDURE WITH HIGH CAUTION
# TO AVOID UNINTENDED EXECUTION RIGHT REVOCATION!
#
==================================================================================================*/
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 @ProcedureNamePattern is null or @UserOrGroupName is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:RevokeExecOnProcedures'

if CHARINDEX(' ',@ProcedureNamePattern)>0 or
   @ProcedureNamePattern='%' or SUBSTRING(@ProcedureNamePattern,1,2)='%%'
   exec [AUX:RaiseError] 'AUX:RevokeExecOnProcedures',
      'Incorrect pattern for procedure name.',
      N'Некорректный шаблон имени процедуры.'

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

declare @PROCEDURE_LIST table ([Name] sysname primary key)
insert @PROCEDURE_LIST
   select [name] from [sysobjects] (nolock)
   where [type]='P' and [name] like @ProcedureNamePattern escape '\'

while 0=0
begin
   declare @ProcedureName sysname
   select @ProcedureName=MIN([Name]) from @PROCEDURE_LIST
   if @ProcedureName is null break

   exec( 'revoke execute on ['+@ProcedureName+'] to ['+@UserOrGroupName+']' )

   delete @PROCEDURE_LIST where [Name] = @ProcedureName
end

----------------------------------------------------------------------------------------------------
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
--:SetVar Procedure "AUX:SubstEmptyWithNull"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:SubstEmptyWithNull' )
   drop procedure [AUX:SubstEmptyWithNull]
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:SubstEmptyWithNull] @String nvarchar(max) out
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# EMPTY STRING SUBSTITUTION WITH NULL (PROCEDURE):
#
# === Usage: ===
# exec [AUX:SubstEmptyWithNull] @<String variable> out
#
==================================================================================================*/
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
----------------------------------------------------------------------------------------------------

set @String = dbo.[AUX:EmptyAsNull]( @String )

----------------------------------------------------------------------------------------------------
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
/*
declare @String nvarchar(max)
set @String = N'qwerty'
exec [AUX:SubstEmptyWithNull] @String out
select '“'+@String+'”' 'Empty string as null'
*/
/*
declare @String nvarchar(max)
set @String = ''
exec [AUX:SubstEmptyWithNull] @String out
select '“'+@String+'”' 'Empty string as null'
*/
/*
declare @String nvarchar(max)
set @String = ' '
exec [AUX:SubstEmptyWithNull] @String out
select '“'+@String+'”' 'Empty string as null'
*/
--:SetVar Procedure "AUX:TrimEndingSpaces"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:TrimEndingSpaces' )
   drop procedure [AUX:TrimEndingSpaces]
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:TrimEndingSpaces] @String nvarchar(max) out
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# TRIMMING OF TAIL SPACES (PROCEDURE):
#
# === Usage: ===
# exec [AUX:TrimEndingSpaces] @<String variable> out
#
==================================================================================================*/
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
----------------------------------------------------------------------------------------------------

set @String = RTRIM( @String )

----------------------------------------------------------------------------------------------------
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
/*
declare @String nvarchar(max)
set @String = N'   12345     '
exec [AUX:TrimEndingSpaces] @String out
select '“'+@String+'”' 'String without tail spaces'
*/
--:SetVar Procedure "AUX:TrimSpaces"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:TrimSpaces' )
   drop procedure [AUX:TrimSpaces]
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:TrimSpaces] @String nvarchar(max) out
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# TRIMMING OF BOUNDING SPACES (PROCEDURE):
#
# === Usage: ===
# exec [AUX:TrimSpaces] @<String variable> out
#
==================================================================================================*/
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
----------------------------------------------------------------------------------------------------

set @String = TRIM( @String )

----------------------------------------------------------------------------------------------------
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
/*
declare @String nvarchar(max)
set @String = N'   12345     '
exec [AUX:TrimSpaces] @String out
select '“'+@String+'”' 'String without bounding spaces'
*/
--:SetVar Procedure "AUX:TryMakeDateFromStr"
if exists( select * from [sysobjects] (nolock) where [type]='P' and [name]=N'AUX:TryMakeDateFromStr' )
   drop procedure [AUX:TryMakeDateFromStr]
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:TryMakeDateFromStr] @DateString              nvarchar(max),
                                @ResultDate              datetime2 out,
                                @SignificantLengthStrict bit = 0
AS
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# STRING TO DATE CONVERSION ATTEMPT, IN SIMPLE LOCAL FORMAT (ACCODING TO EFFECTIVE LOCALE):
# - INPUT STRING EN: MM/DD/YYYY (DEFAULT LANGUAGE LOCALE);
# - INPUT STRING RU: ДД.ММ.ГГГГ (MAIN LANGUAGE LOCALE);
# - INPUT STRING XX: ...
#
# === Usage: ===
# exec [AUX:TryMakeDateFromStr] <Date-строка>, @<Resulting date variable> out
# exec [AUX:TryMakeDateFromStr] <Date-строка>, @<Resulting date variable> out, 1
#
# Return values
# : 0 ————————— success;
# : not zero —— error
#
==================================================================================================*/
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 @DateString is null
   exec [AUX:RaiseIncorrectProcedureCall] 'AUX:TryMakeDateFromStr'

----------------------------------------------------------------------------------------------------
set @ResultDate = null

if @DateString = TRIM( @DateString )

if CHARINDEX(' ',@DateString) > 0
   return 1

declare @Length int
set @Length = LEN( @DateString )
if @Length not between 9 and 10 or
   @SignificantLengthStrict=1 and @Length<>10
   return 1

declare @IsInMainLanguageLocale bit, @IsInDefaultLangLocale bit
select
   @IsInMainLanguageLocale = dbo.[AUX:IsInMainLanguageLocale](), -- RU
   @IsInDefaultLangLocale = dbo.[AUX:IsInDefaultLangLocale]()
if @IsInMainLanguageLocale = 1 or @IsInDefaultLangLocale = 1
begin
   declare @P int, @Ch nchar
   set @P = 1
   while @P <= @Length
   begin
      set @Ch = SUBSTRING( @DateString, @P, 1 )
      if @Ch not between '0' and '9' and (
         @IsInMainLanguageLocale = 1 and @Ch<>'.' or
         @IsInDefaultLangLocale = 1 and @Ch<>'/' )
         return 1
      set @P = @P + 1
   end
end

declare @Date datetime2
begin try
   set @Date = CONVERT( datetime2, @DateString, dbo.[AUX:DateFormat]() )
end try
begin catch
   return 1
end catch

if dbo.[AUX:IsPureDate]( @Date ) = 0
   return 1

set @ResultDate = @Date

----------------------------------------------------------------------------------------------------
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
/*
declare @Date datetime2
exec [AUX:TryMakeDateFromStr] '10/12/2015', @Date out; select @Date '10/12/2015'
exec [AUX:TryMakeDateFromStr] '10/02/2015', @Date out; select @Date '10/02/2015'
exec [AUX:TryMakeDateFromStr] '10/02/2015', @Date out, 1; select @Date '10/02/2015'
exec [AUX:TryMakeDateFromStr] N'AB/02/2015', @Date out; select @Date N'AB/02/2015'
*/
/*
declare @Date datetime2
exec [AUX:TryMakeDateFromStr] '12.10.2015', @Date out; select @Date '12.10.2015'
exec [AUX:TryMakeDateFromStr] '2.10.2015', @Date out; select @Date '2.10.2015'
exec [AUX:TryMakeDateFromStr] '2.10.2015', @Date out, 1; select @Date '2.10.2015'
exec [AUX:TryMakeDateFromStr] N'02.ЙЫ.2015', @Date out; select @Date N'2.ЙЫ.2015'
*/
