/*==================================================================================================
#
# 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
/*==================================================================================================
#
# DELETION OF ALL FUNCTIONS 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 @FUNCTION_LIST table ([Name] sysname primary key)
insert @FUNCTION_LIST
   select [name] from [sysobjects] (nolock)
   where [type] in ('FN','TF') 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 @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
/*==================================================================================================
#
# REMOVING OF ALL AUXILIARY TABLES 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
----------------------------------------------------------------------------------------------------
--:SetVar DropTable "if OBJECT_ID(@TableName,'U') is not null exec( 'drop table ['+@TableName+']' )"
----------------------------------------------------------------------------------------------------
declare @TableName nvarchar(max)
----------------------------------------------------------------------------------------------------
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
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

set @TableName='AUX::Month_list:En';   if OBJECT_ID(@TableName,'U') is not null exec( 'drop table ['+@TableName+']' );
set @TableName='AUX::Month_list:Ru';   if OBJECT_ID(@TableName,'U') is not null exec( 'drop table ['+@TableName+']' );
set @TableName='AUX::WeekDay_list:En'; if OBJECT_ID(@TableName,'U') is not null exec( 'drop table ['+@TableName+']' );
set @TableName='AUX::WeekDay_list:Ru'; if OBJECT_ID(@TableName,'U') is not null exec( 'drop table ['+@TableName+']' );
set @TableName='AUX::Roman_numbers';   if OBJECT_ID(@TableName,'U') is not null exec( 'drop table ['+@TableName+']' );

-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
/*==================================================================================================
#
# REMOVING OF ALL AUXILIARY TABLES 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
----------------------------------------------------------------------------------------------------
--:SetVar DropTable "if OBJECT_ID(@TableName,'U') is not null exec( 'drop table ['+@TableName+']' )"
----------------------------------------------------------------------------------------------------
declare @TableName nvarchar(max)
----------------------------------------------------------------------------------------------------
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
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

set @TableName='AUX::Month_list:En';   if OBJECT_ID(@TableName,'U') is not null exec( 'drop table ['+@TableName+']' );
set @TableName='AUX::Month_list:Ru';   if OBJECT_ID(@TableName,'U') is not null exec( 'drop table ['+@TableName+']' );
set @TableName='AUX::WeekDay_list:En'; if OBJECT_ID(@TableName,'U') is not null exec( 'drop table ['+@TableName+']' );
set @TableName='AUX::WeekDay_list:Ru'; if OBJECT_ID(@TableName,'U') is not null exec( 'drop table ['+@TableName+']' );
set @TableName='AUX::Roman_numbers';   if OBJECT_ID(@TableName,'U') is not null exec( 'drop table ['+@TableName+']' );

-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
/*==================================================================================================
#
# CREATION OF CALENDAR MONTH LIST TABLE — ENGLISH LANGUAGE:
#
==================================================================================================*/
--:SetVar Table "AUX::Month_list:En"
----------------------------------------------------------------------------------------------------
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
----------------------------------------------------------------------------------------------------
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
----------------------------------------------------------------------------------------------------
if exists( select * from [sysobjects] (nolock) where [type]='U' and [name]=N'AUX::Month_list:En' ) drop table [AUX::Month_list:En];
----------------------------------------------------------------------------------------------------
create table [AUX::Month_list:En]
(
   [NO]     int         not null,
   [Name]   varchar(9)  not null
   constraint
      [PK:AUX::Month_list:En]
      primary key ( [NO] )
)
----------------------------------------------------------------------------------------------------
insert [AUX::Month_list:En]
values
(  1, 'January'   ),
(  2, 'February'  ),
(  3, 'March'     ),
(  4, 'April'     ),
(  5, 'May'       ),
(  6, 'June'      ),
(  7, 'July'      ),
(  8, 'August'    ),
(  9, 'September' ),
( 10, 'October'   ),
( 11, 'November'  ),
( 12, 'December'  )
----------------------------------------------------------------------------------------------------
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
/*
select * from [AUX::Month_list:En]
*/
/*==================================================================================================
#
# CREATION OF CALENDAR MONTH LIST TABLE — RUSSIAN LANGUAGE:
#
==================================================================================================*/
--:SetVar Table "AUX::Month_list:Ru"
----------------------------------------------------------------------------------------------------
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
----------------------------------------------------------------------------------------------------
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
----------------------------------------------------------------------------------------------------
if exists( select * from [sysobjects] (nolock) where [type]='U' and [name]=N'AUX::Month_list:Ru' ) drop table [AUX::Month_list:Ru];
----------------------------------------------------------------------------------------------------
create table [AUX::Month_list:Ru]
(
   [NO]              int         not null,
   [Name]            nvarchar(8) not null,
   [InGenitiveCase]  nvarchar(8) not null
   constraint
      [PK:AUX::Month_list:Ru]
      primary key ( [NO] )
)
----------------------------------------------------------------------------------------------------
insert [AUX::Month_list:Ru]
values
(  1, N'Январь'  , N'Января'   ),
(  2, N'Февраль' , N'Февраля'  ),
(  3, N'Март'    , N'Марта'    ),
(  4, N'Апрель'  , N'Апреля'   ),
(  5, N'Май'     , N'Мая'      ),
(  6, N'Июнь'    , N'Июня'     ),
(  7, N'Июль'    , N'Июля'     ),
(  8, N'Август'  , N'Августа'  ),
(  9, N'Сентябрь', N'Сентября' ),
( 10, N'Октябрь' , N'Октября'  ),
( 11, N'Ноябрь'  , N'Ноября'   ),
( 12, N'Декабрь' , N'Декабря'  )
----------------------------------------------------------------------------------------------------
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
/*
select * from [AUX::Month_list:Ru]
*/
/*==================================================================================================
#
# CREATION OF ROMAN NUMBER LIST TABLE (INSCRIPTIONS) — [1...100]:
#
==================================================================================================*/
--:SetVar Table "AUX::Roman_numbers"
----------------------------------------------------------------------------------------------------
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
----------------------------------------------------------------------------------------------------
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
----------------------------------------------------------------------------------------------------
if exists( select * from [sysobjects] (nolock) where [type]='U' and [name]=N'AUX::Roman_numbers' ) drop table [AUX::Roman_numbers];
----------------------------------------------------------------------------------------------------
create table [AUX::Roman_numbers]
(
   [Number]    int                     not null,
   [Display]   varchar(8)   not null
   constraint
      [PK:AUX::Roman_numbers]
      primary key ( [Number] )
)
----------------------------------------------------------------------------------------------------
insert [AUX::Roman_numbers] values
(  1, 'I'         ),
(  2, 'II'        ),
(  3, 'III'       ),
(  4, 'IV'        ),
(  5, 'V'         ),
(  6, 'VI'        ),
(  7, 'VII'       ),
(  8, 'VIII'      ),
(  9, 'IX'        ),
( 10, 'X'         )

insert [AUX::Roman_numbers] values
( 11, 'XI'        ),
( 12, 'XII'       ),
( 13, 'XIII'      ),
( 14, 'XIV'       ),
( 15, 'XV'        ),
( 16, 'XVI'       ),
( 17, 'XVII'      ),
( 18, 'XVIII'     ),
( 19, 'XIX'       ),
( 20, 'XX'        )

insert [AUX::Roman_numbers] values
( 21, 'XXI'       ),
( 22, 'XXII'      ),
( 23, 'XXIII'     ),
( 24, 'XXIV'      ),
( 25, 'XXV'       ),
( 26, 'XXVI'      ),
( 27, 'XXVII'     ),
( 28, 'XXVIII'    ),
( 29, 'XXIX'      ),
( 30, 'XXX'       )

insert [AUX::Roman_numbers] values
( 31, 'XXXI'      ),
( 32, 'XXXII'     ),
( 33, 'XXXIII'    ),
( 34, 'XXXIV'     ),
( 35, 'XXXV'      ),
( 36, 'XXXVI'     ),
( 37, 'XXXVII'    ),
( 38, 'XXXVIII'   ),
( 39, 'XXXIX'     ),
( 40, 'XL'        )

insert [AUX::Roman_numbers] values
( 41, 'XLI'       ),
( 42, 'XLII'      ),
( 43, 'XLIII'     ),
( 44, 'XLIV'      ),
( 45, 'XLV'       ),
( 46, 'XLVI'      ),
( 47, 'XLVII'     ),
( 48, 'XLVIII'    ),
( 49, 'XLIX'      ),
( 50, 'L'         )

insert [AUX::Roman_numbers] values
( 51, 'LI'        ),
( 52, 'LII'       ),
( 53, 'LIII'      ),
( 54, 'LIV'       ),
( 55, 'LV'        ),
( 56, 'LVI'       ),
( 57, 'LVII'      ),
( 58, 'LVIII'     ),
( 59, 'LIX'       ),
( 60, 'LX'        )

insert [AUX::Roman_numbers] values
( 61, 'LXI'       ),
( 62, 'LXII'      ),
( 63, 'LXIII'     ),
( 64, 'LXIV'      ),
( 65, 'LXV'       ),
( 66, 'LXVI'      ),
( 67, 'LXVII'     ),
( 68, 'LXVIII'    ),
( 69, 'LXIX'      ),
( 70, 'LXX'       )

insert [AUX::Roman_numbers] values
( 71, 'LXXI'      ),
( 72, 'LXXII'     ),
( 73, 'LXXIII'    ),
( 74, 'LXXIV'     ),
( 75, 'LXXV'      ),
( 76, 'LXXVI'     ),
( 77, 'LXXVII'    ),
( 78, 'LXXVIII'   ),
( 79, 'LXXIX'     ),
( 80, 'LXXX'      )

insert [AUX::Roman_numbers] values
( 81, 'LXXXI'     ),
( 82, 'LXXXII'    ),
( 83, 'LXXXIII'   ),
( 84, 'LXXXIV'    ),
( 85, 'LXXXV'     ),
( 86, 'LXXXVI'    ),
( 87, 'LXXXVII'   ),
( 88, 'LXXXVIII'  ),
( 89, 'LXXXIX'    ),
( 90, 'XC'        )

insert [AUX::Roman_numbers] values
( 91, 'XCI'       ),
( 92, 'XCII'      ),
( 93, 'XCIII'     ),
( 94, 'XCIV'      ),
( 95, 'XCV'       ),
( 96, 'XCVI'      ),
( 97, 'XCVII'     ),
( 98, 'XCVIII'    ),
( 99, 'XCIX'      ),
(100, 'C'         )
----------------------------------------------------------------------------------------------------
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
/*
select * from [AUX::Roman_numbers]
*/
/*==================================================================================================
#
# CREATION OF WEEK DAY LIST TABLE — ENGLISH LANGUAGE:
#
==================================================================================================*/
--:SetVar Table "AUX::WeekDay_list:En"
----------------------------------------------------------------------------------------------------
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
----------------------------------------------------------------------------------------------------
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
----------------------------------------------------------------------------------------------------
if exists( select * from [sysobjects] (nolock) where [type]='U' and [name]=N'AUX::WeekDay_list:En' ) drop table [AUX::WeekDay_list:En];
----------------------------------------------------------------------------------------------------
create table [AUX::WeekDay_list:En]
(
   [ID]              int         not null,
   [FromSundayNo]    int         not null,
   [FromMondayNo]    int         not null,
   [Name]            varchar(9)  not null
   constraint
      [PK:AUX::WeekDay_list:En]
      primary key ( [ID] ),
   constraint
      [UQ:AUX::WeekDay_list:En.FromSundayNo]
      unique ( [FromSundayNo] ),
   constraint
      [UQ:AUX::WeekDay_list:En.FromMondayNo]
      unique ( [FromMondayNo] )
)
----------------------------------------------------------------------------------------------------
insert [AUX::WeekDay_list:En]
values
(  0, 1, 7, 'Sunday'    ),
(  1, 2, 1, 'Monday'    ),
(  2, 3, 2, 'Tuesday'   ),
(  3, 4, 3, 'Wednesday' ),
(  4, 5, 4, 'Thursday'  ),
(  5, 6, 5, 'Friday'    ),
(  6, 7, 6, 'Saturday'  )
----------------------------------------------------------------------------------------------------
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
/*
select * from [AUX::WeekDay_list:En]
*/
/*==================================================================================================
#
# CREATION OF WEEK DAY LIST TABLE — RUSSIAN LANGUAGE:
#
==================================================================================================*/
--:SetVar Table "AUX::WeekDay_list:Ru"
----------------------------------------------------------------------------------------------------
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
----------------------------------------------------------------------------------------------------
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
----------------------------------------------------------------------------------------------------
if exists( select * from [sysobjects] (nolock) where [type]='U' and [name]=N'AUX::WeekDay_list:Ru' ) drop table [AUX::WeekDay_list:Ru];
----------------------------------------------------------------------------------------------------
create table [AUX::WeekDay_list:Ru]
(
   [ID]              int            not null,
   [FromSundayNo]    int            not null,
   [FromMondayNo]    int            not null,
   [Name]            nvarchar(11)   not null
   constraint
      [PK:AUX::WeekDay_list:Ru]
      primary key ( [ID] ),
   constraint
      [UQ:AUX::WeekDay_list:Ru.FromSundayNo]
      unique ( [FromSundayNo] ),
   constraint
      [UQ:AUX::WeekDay_list:Ru.FromMondayNo]
      unique ( [FromMondayNo] )
)
----------------------------------------------------------------------------------------------------
insert [AUX::WeekDay_list:Ru]
values
(  0, 1, 7, 'Воскресенье' ),
(  1, 2, 1, 'Понедельник' ),
(  2, 3, 2, 'Вторник'     ),
(  3, 4, 3, 'Среда'       ),
(  4, 5, 4, 'Четверг'     ),
(  5, 6, 5, 'Пятница'     ),
(  6, 7, 6, 'Суббота'     )
----------------------------------------------------------------------------------------------------
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
/*
select * from [AUX::WeekDay_list:Ru]
*/
/*==================================================================================================
#
# DELETION OF ALL FUNCTIONS 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 @FUNCTION_LIST table ([Name] sysname primary key)
insert @FUNCTION_LIST
   select [name] from [sysobjects] (nolock)
   where [type] in ('FN','TF') 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 @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 Function "AUX:MainLanguageId"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:MainLanguageId' )
   drop function [AUX:MainLanguageId]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:MainLanguageId]()
returns int -- null
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# MAIN LIBRARY-LANGUAGE IDENTIFIER ($(num_MainLanguageId_AUX)):
#
# === Usage: ===
# dbo.[AUX:MainLanguageId]()
#
==================================================================================================*/
return 21
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:MainLanguageId]() 'Main language ID'
*/
--:SetVar Function "AUX:DefaultLanguageId"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:DefaultLanguageId' )
   drop function [AUX:DefaultLanguageId]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:DefaultLanguageId]()
returns int -- null
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DEFAULT LIBRARY-LANGUAGE IDENTIFIER ($(num_DefaultLanguageId_AUX)):
#
# === Usage: ===
# dbo.[AUX:DefaultLanguageId]()
#
==================================================================================================*/
return 0
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:DefaultLanguageId]() 'Default language ID'
*/
--:SetVar Function "AUX:IsSupportedLanguage"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IsSupportedLanguage' )
   drop function [AUX:IsSupportedLanguage]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IsSupportedLanguage]( @LanguageId int )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CHECKING IF SPECIFIED LANGUAGE IS SUPPORTED BY SQLAUX-LIBRARY:
#
# === Usage: ===
# dbo.[AUX:IsSupportedLanguage]( <Language ID> )
#
==================================================================================================*/
return IIF( @LanguageId in ( 0,21 ), 1, 0 )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IsSupportedLanguage]( 0 ) 'Is English supported'
select dbo.[AUX:IsSupportedLanguage]( 21 ) 'Is Russial supported'
select dbo.[AUX:IsSupportedLanguage]( 2 ) 'Is French supported'
*/
--:SetVar Function "AUX:UseMainLanguageForFallback"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:UseMainLanguageForFallback' )
   drop function [AUX:UseMainLanguageForFallback]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:UseMainLanguageForFallback]()
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# USAGE OF MAIN LANGUAGE FOR “FALLBACK”-PROCEDURE (IN LOCALIZATION):
#
# === Usage: ===
# dbo.[AUX:UseMainLanguageForFallback]()
#
==================================================================================================*/
return 0
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:UseMainLanguageForFallback]() 'Use main language for fallback'
*/
--:SetVar Function "AUX:OverrideLanguageWithMain"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:OverrideLanguageWithMain' )
   drop function [AUX:OverrideLanguageWithMain]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:OverrideLanguageWithMain]()
returns bit
BEGIN
/*================================================================================================*/
/* SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# MAIN LANGUAGE DOMINANCE FLAG (OVER CURRENT “@@LANGID”):
#
# === Usage: ===
# dbo.[AUX:OverrideLanguageWithMain]()
*/
/*================================================================================================*/
return 0
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:OverrideLanguageWithMain]() 'Override language with main'
*/
--:SetVar Function "AUX:LocalLanguageName"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:LocalLanguageName' )
   drop function [AUX:LocalLanguageName]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:LocalLanguageName]()
returns nvarchar(50) -- null
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOCAL-LANGUAGE IDENTIFIER FROM CONNECTION PROPERTIES (“Application Name=...#Xxxxx”):
#
# === Usage: ===
# dbo.[AUX:LocalLanguageName]()
#
==================================================================================================*/
declare @AppName sysname
select @AppName = [program_name] from [sysprocesses] (nolock) where [spid] = @@SPID
if @AppName is null
   return null
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
declare @L int, @P int
set @L = LEN( @AppName )
set @P = @L
while @P > 0
begin
   if SUBSTRING( @AppName, 1, 1 ) = '#' break
   set @P = @P - 1
end
if @P > 0 and @P < @L
   return dbo.[AUX:LocalLanguageNameFromCulture]( SUBSTRING( @AppName, @P+1, @L-@P ) )
return null
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:LocalLanguageName]() 'Current local-language'
*/
--:SetVar Function "AUX:SpecialLanguage"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:SpecialLanguage' )
   drop function [AUX:SpecialLanguage]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:SpecialLanguage]()
returns nvarchar(100)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# SPECIAL LANGUAGE NAME FROM CONNECTION STRING —
# FOR SITUATION, WHEN THE LANGUAGE IS NOT SUPPORTED BY MS-SQL-SERVER:
#
# === Examples: ===
# Connection string: "...;Application Name=...#Old Slavonic;..."
# Connection string: "...;Application Name=...#OSL;..."
#
# === Usage: ===
# dbo.[AUX:SpecialLanguage]()
#
==================================================================================================*/
declare @AppName sysname
select @AppName = [program_name] from [sysprocesses] (nolock) where [spid] = @@SPID
if @AppName is null or CHARINDEX('#',@AppName)=0
   return null
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
declare @L int, @P int
set @L = LEN( @AppName )
set @P = @L
while @P > 0
begin
   if SUBSTRING(@AppName,1,1)='#' break
   set @P = @P - 1
end
if @P > 0 and @P < @L
   return dbo.[AUX:LocalLanguageNameFromCulture]( SUBSTRING( @AppName, @P+1, @L-@P ) )
return null
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:SpecialLanguage]() 'Special language (from connection string)'
*/
--:SetVar Function "AUX:ActiveLanguage"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ActiveLanguage' )
   drop function [AUX:ActiveLanguage]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ActiveLanguage]()
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# ACTIVE LANGUAGE SQL-IDENTIFIER OF SQLAUX-LIBRARY
# (“XLANG_N”-IDS/SPECIAL ARE INTERPRETED AS NEGATIVE NUMERIC VALUES.)
#
# === Usage: ===
# dbo.[AUX:ActiveLanguage]()
#
==================================================================================================*/
if dbo.[AUX:OverrideLanguageWithMain]()=1
   return 21
----------------------------------------------------------------------------------------------------
declare @SpecialLanguage nvarchar(100)
set @SpecialLanguage = dbo.[AUX:SpecialLanguage]()
if @SpecialLanguage is not null
begin
   if @SpecialLanguage = null return -1
   if @SpecialLanguage = null return -2
end
----------------------------------------------------------------------------------------------------
declare @LanguageId int
set @LanguageId = @@LANGID
if dbo.[AUX:IsSupportedLanguage]( @LanguageId ) = 1
   return
      case @LanguageId 
         when null then -1
         when null then -2
         else @LanguageId
      end
----------------------------------------------------------------------------------------------------
return IIF(
   dbo.[AUX:UseMainLanguageForFallback]()=1,
   21,
   0 )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ActiveLanguage]() 'Active language ID'
*/
--:SetVar Function "AUX:IsInMainLanguageLocale"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IsInMainLanguageLocale' )
   drop function [AUX:IsInMainLanguageLocale]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IsInMainLanguageLocale]()
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# TAG OF LOCATION IN MAIN LANGUAGE LOCALE:
#
# === Usage: ===
# dbo.[AUX:IsInMainLanguageLocale]()
#
==================================================================================================*/
return IIF( dbo.[AUX:ActiveLanguage]() = 21, 1, 0 )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IsInMainLanguageLocale]() 'Is in main language locale'
*/
--:SetVar Function "AUX:IsInDefaultLangLocale"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IsInDefaultLangLocale' )
   drop function [AUX:IsInDefaultLangLocale]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IsInDefaultLangLocale]()
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# TAG OF LOCATION IN DEFAULT LANGUAGE LOCALE:
#
# === Usage: ===
# dbo.[AUX:IsInDefaultLangLocale]()
#
==================================================================================================*/
return IIF( dbo.[AUX:ActiveLanguage]() = 0, 1, 0 )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IsInDefaultLangLocale]() 'Is in default language locale'
*/
--:SetVar Function "AUX:LocalizedText.X2"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:LocalizedText.X2' )
   drop function [AUX:LocalizedText.X2]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:LocalizedText.X2]
(
   @DefaultText      nvarchar(max),
   @InMainLanguage   nvarchar(max) = null,
   @XLangText_1      nvarchar(max) = null,
   @XLangText_2      nvarchar(max) = null
)
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOCALIZED TEXT (PLUS TWO ADDITIONAL LANGUAGES):
#
# === Usage: ===
# dbo.[AUX:LocalizedText.X2]( <Default text>, null, null, null )
# dbo.[AUX:LocalizedText.X2]( <Default text>, <Text in main language>, null, null )
# dbo.[AUX:LocalizedText.X2]( <Default text>, <Text in main language>,
#                             <Local text-1>, null )
# dbo.[AUX:LocalizedText.X2]( <Default text>, <Text in main language>,
#                             <Local text-1>, <Local text-2> )
#
==================================================================================================*/

if dbo.[AUX:OverrideLanguageWithMain]() = 1
   return ISNULL( @InMainLanguage, @DefaultText )

return
   case dbo.[AUX:ActiveLanguage]()
      when 21 then @InMainLanguage
      when -1 then @XLangText_1
      when -2 then @XLangText_2
      else IIF( dbo.[AUX:UseMainLanguageForFallback]()=1, @InMainLanguage, @DefaultText )
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:LocalizedText.X2]( N'Привет!', null, null, null ) 'Greeting'
select dbo.[AUX:LocalizedText.X2]( 'Hello!', N'Привет!', null, null ) 'Greeting'
*/
--:SetVar Function "AUX:LocalizedText.X1"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:LocalizedText.X1' )
   drop function [AUX:LocalizedText.X1]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:LocalizedText.X1]
(
   @DefaultText      nvarchar(max),
   @InMainLanguage   nvarchar(max) = null,
   @XLangText_1      nvarchar(max) = null
)
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOCALIZED TEXT (PLUS ONE ADDITIONAL LANGUAGE):
#
# === Usage: ===
# dbo.[AUX:LocalizedText.X1]( <Default text>, null, null )
# dbo.[AUX:LocalizedText.X1]( <Default text>, <Text in main language>, null )
# dbo.[AUX:LocalizedText.X1]( <Default text>, <Text in main language>, <Local text-1> )
#
==================================================================================================*/
return dbo.[AUX:LocalizedText.X2]( @DefaultText, @InMainLanguage, @XLangText_1, null )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:LocalizedText.X1]( N'Привет!', null, null ) 'Greeting'
select dbo.[AUX:LocalizedText.X1]( 'Hello!', N'Привет!', null ) 'Greeting'
*/
--:SetVar Function "AUX:LocalizedText"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:LocalizedText' )
   drop function [AUX:LocalizedText]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:LocalizedText]
(
   @DefaultText      nvarchar(max),
   @InMainLanguage   nvarchar(max) = null
)
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOCALIZED TEXT (ONE OF TWO VARIANTS):
#
# === Usage: ===
# dbo.[AUX:LocalizedText]( <Default text>, null )
# dbo.[AUX:LocalizedText]( <Default text>, <Text in main language> )
#
==================================================================================================*/
return dbo.[AUX:LocalizedText.X2]( @DefaultText, @InMainLanguage, null, null )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:LocalizedText]( N'Привет!', null ) 'Greeting'
select dbo.[AUX:LocalizedText]( 'Hello!', N'Привет!' ) 'Greeting'
*/
--:SetVar Function "AUX:TechLanguage"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:TechLanguage' )
   drop function [AUX:TechLanguage]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:TechLanguage]()
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# TECHNICAL LANGUAGE SQL-IDENTIFIER OF SQLAUX-LIBRARY —
# FOR TECH.ERROR MESSAGES (DEVELOPMENT/MAINTENANCE, SCENARIO OF LOCAL SQL-SERVER USAGE, ETC.):
#
# === Usage: ===
# dbo.[AUX:TechLanguage]()
#
==================================================================================================*/
return IIF( dbo.[AUX:OverrideLanguageWithMain]() = 1,
   21, 0 )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:TechLanguage]() 'Technical language ID'
*/
--:SetVar Function "AUX:TechLocalText"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:TechLocalText' )
   drop function [AUX:TechLocalText]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:TechLocalText]
(
   @DefaultText      nvarchar(max),
   @InMainLanguage   nvarchar(max) = null
)
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOCALIZED TEXT, ACCORDING TO TECHNICAL LANGUAGE OF SQLAUX-LIBRARY —
# FOR TECH.ERROR MESSAGES (DEVELOPMENT/MAINTENANCE, SCENARIO OF LOCAL SQL-SERVER USAGE, ETC.):
#
# === Usage: ===
# dbo.[AUX:TechLocalText]( <Default text>, null )
# dbo.[AUX:TechLocalText]( <Default text>, <Text in main language> )
#
==================================================================================================*/
return IIF( dbo.[AUX:TechLanguage]()=21, @InMainLanguage, @DefaultText )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:TechLocalText]( N'Привет!', null ) 'Greeting'
select dbo.[AUX:TechLocalText]( 'Hello!', N'Привет!' ) 'Greeting'
*/
--:SetVar Function "AUX:DateFormat"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:DateFormat' )
   drop function [AUX:DateFormat]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:DateFormat]()
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DATE FORMAT IDENTIFIER (IN CORRESPONCENCE TO SQL LOCALE, OR WITH ITS OVERRIDING):
#
# === Usage: ===
# dbo.[AUX:DateFormat]()
#
==================================================================================================*/
declare @LanguageId int
set @LanguageId = dbo.[AUX:ActiveLanguage]()
if @LanguageId=0 goto IN_ENGLISH
if @LanguageId=21 goto IN_RUSSIAN
--if @LanguageId=-1 goto IN_XLANG_1
--if @LanguageId=-2 goto IN_XLANG_2
goto IN_ENGLISH
----------------------------------------------------------------------------------------------------
IN_ENGLISH:
   return 101 -- MM/DD/YYYY
IN_RUSSIAN:
   return 104 -- DD.MM.YYYY
/*
IN_XLANG_1:
   return ... -- 
IN_XLANG_2:
   return ... -- 
*/
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:DateFormat]() 'Date format (code)'
*/
--:SetVar Function "AUX:TimeFormat"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:TimeFormat' )
   drop function [AUX:TimeFormat]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:TimeFormat]()
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# TIME FORMAT IDENTIFIER (IN CORRESPONCENCE TO SQL LOCALE, OR WITH ITS OVERRIDING):
#
# === Usage: ===
# dbo.[AUX:TimeFormat]()
#
==================================================================================================*/
declare @LanguageId int
set @LanguageId = dbo.[AUX:ActiveLanguage]()
if @LanguageId=0 goto IN_ENGLISH
if @LanguageId=21 goto IN_RUSSIAN
--if @LanguageId=-1 goto IN_XLANG_1
--if @LanguageId=-2 goto IN_XLANG_2
goto IN_ENGLISH
----------------------------------------------------------------------------------------------------
IN_ENGLISH:
   return 108 -- HH:MM:SS
IN_RUSSIAN:
   return 108 -- HH:MM:SS
/*
IN_XLANG_1:
   return ... -- 
IN_XLANG_2:
   return ... -- 
*/
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:TimeFormat]() 'Time format (code)'
*/
--:SetVar Function "AUX:StrLength"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:StrLength' )
   drop function [AUX:StrLength]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:StrLength]( @String nvarchar(max) )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# STRING LENGTH (CONSIDERING ENDING SPACES):
#
# === Usage: ===
# dbo.[AUX:StrLength]( <String> )
#
==================================================================================================*/

return DATALENGTH( @String ) / 2

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:StrLength]( N'12345     ' ) 'String length'
select dbo.[AUX:StrLength]( CONVERT(nvarchar(max),N'12345     ') ) 'String length'
*/
--:SetVar Function "AUX:PadStart.Ext"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:PadStart.Ext' )
   drop function [AUX:PadStart.Ext]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:PadStart.Ext]
(
   @String           nvarchar(max),
   @WidthForPadding  int,
   @PadChar          nchar
)
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# STRING COMPLEMENT FROM START, WITH PADDING CHAR OR WITH SPACES (EXT.VERSION):
#
# === Usage: ===
# dbo.[AUX:PadStart.Ext]( <String>, <Width for padding>, null )
# dbo.[AUX:PadStart.Ext]( <String>, <Width for padding>, <Padding character> )
#
==================================================================================================*/

if @String is null or @WidthForPadding is null
   return @String

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

declare @Length int
set @Length = dbo.[AUX:StrLength]( @String )

if @WidthForPadding <= @Length
   return @String

return
   REPLICATE( ISNULL(@PadChar,' '), @WidthForPadding - @Length ) +
   @String

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:PadStart.Ext]( N'string', 10, null )+'”' 'Complemented string'
select '“'+dbo.[AUX:PadStart.Ext]( N'string', 10, '_' )+'”' 'Complemented string'
select '“'+dbo.[AUX:PadStart.Ext]( N'string', 5, null )+'”' 'Complemented string'
select '“'+dbo.[AUX:PadStart.Ext]( N'string', 5, '_' )+'”' 'Complemented string'
*/
--:SetVar Function "AUX:PadEnd.Ext"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:PadEnd.Ext' )
   drop function [AUX:PadEnd.Ext]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:PadEnd.Ext]
(
   @String           nvarchar(max),
   @WidthForPadding  int,
   @PadChar          nchar
)
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# STRING COMPLEMENT FROM END, WITH PADDING CHAR OR WITH SPACES (EXT.VERSION):
#
# === Usage: ===
# dbo.[AUX:PadEnd.Ext]( <String>, <Width for padding>, null )
# dbo.[AUX:PadEnd.Ext]( <String>, <Width for padding>, <Padding character> )
#
==================================================================================================*/

if @String is null or @WidthForPadding is null
   return @String

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

declare @Length int
set @Length = dbo.[AUX:StrLength]( @String )

if @WidthForPadding <= @Length
   return @String

return
   @String +
   REPLICATE( ISNULL(@PadChar,' '), @WidthForPadding - @Length )

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:PadEnd.Ext]( N'string', 10, null )+'”' 'Complemented string'
select '“'+dbo.[AUX:PadEnd.Ext]( N'string', 10, '_' )+'”' 'Complemented string'
select '“'+dbo.[AUX:PadEnd.Ext]( N'string', 5, null )+'”' 'Complemented string'
select '“'+dbo.[AUX:PadEnd.Ext]( N'string', 5, '_' )+'”' 'Complemented string'
*/
--:SetVar Function "AUX:StartsFromSpace.Ext"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:StartsFromSpace.Ext' )
   drop function [AUX:StartsFromSpace.Ext]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:StartsFromSpace.Ext]( @String nvarchar(max), @TreatBlankAsEmpty bit=0 )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CHECKING, IF STRING STARTS FROM SPACE (EXT.VERSION):
#
# === Usage: ===
# dbo.[AUX:StartsFromSpace.Ext]( <String>, 1 )
# dbo.[AUX:StartsFromSpace.Ext]( <String>, 0 )
#
==================================================================================================*/

if @String is null or DATALENGTH( @String )=0
   return 0

if SUBSTRING(@String,1,1) <> '' -- has heading non-space
   return 0

if @String = '' -- the string is blank (at this place)
   return
      case @TreatBlankAsEmpty
         when 1 then 0
         when 0 then 1
         else null
      end

return 1

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:StartsFromSpace.Ext]( N'qwerty', 1 ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( N' qwerty', 1 ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( ' ', 1 ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( '', 1 ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( null, 1 ) 'Starts from space'
*/
/*
select dbo.[AUX:StartsFromSpace.Ext]( N'qwerty', null ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( N' qwerty', null ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( ' ', null ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( '', null ) 'Starts from space'
select dbo.[AUX:StartsFromSpace.Ext]( null, null ) 'Starts from space'
*/
--:SetVar Function "AUX:BitInversion"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:BitInversion' )
   drop function [AUX:BitInversion]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:BitInversion]( @Value bit )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOGICAL FLAG INVERSION (1/0; “BIT” TYPE):
#
# === Usage: ===
# dbo.[AUX:BitInversion]( <Value> )
#
==================================================================================================*/

return
   case @Value
      when 0 then 1
      when 1 then 0
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:BitInversion]( 0 ) 'Logical flag inversion of 0'
select dbo.[AUX:BitInversion]( 1 ) 'Logical flag inversion of 1'
select dbo.[AUX:BitInversion]( null ) 'Logical flag inversion of null'
*/
--:SetVar Function "AUX:EmptyAsNull"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:EmptyAsNull' )
   drop function [AUX:EmptyAsNull]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:EmptyAsNull]( @String nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# SUBSTITUTION OF EMPTY STRING WITH NULL:
#
# === Usage: ===
# dbo.[AUX:EmptyAsNull]( <String> )
#
==================================================================================================*/

return IIF( @String<>'', @String, null )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:EmptyAsNull]( N'qwerty' ) 'Empty string as null'
select dbo.[AUX:EmptyAsNull]( '' ) 'Empty string as null'
select dbo.[AUX:EmptyAsNull]( ' ' ) 'Empty string as null'
select dbo.[AUX:EmptyAsNull]( null ) 'Empty string as null'
*/
--:SetVar Function "AUX:HasSignificantSpaces"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:HasSignificantSpaces' )
   drop function [AUX:HasSignificantSpaces]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:HasSignificantSpaces]( @String nvarchar(max) )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CHECKING, IF STRING CONTAINS SIGNIFICANT (NON-TRAILING) SPACES:
#
# === Usage: ===
# dbo.[AUX:HasSignificantSpaces]( <String> )
#
==================================================================================================*/

if @String is null or DATALENGTH( @String )=0
   return 0

declare @SpaceIdx int
set @SpaceIdx = CHARINDEX(' ',@String,1)
if @SpaceIdx between 1 and LEN(@String)
   return 1

return 0

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:HasSignificantSpaces]( N'qwerty' ) 'Contains significant spaces'
select dbo.[AUX:HasSignificantSpaces]( N'qwerty ' ) 'Contains significant spaces'
select dbo.[AUX:HasSignificantSpaces]( N'qwer ty' ) 'Contains significant spaces'
select dbo.[AUX:HasSignificantSpaces]( N' qwerty' ) 'Contains significant spaces'
select dbo.[AUX:HasSignificantSpaces]( ' ' ) 'Contains significant spaces'
select dbo.[AUX:HasSignificantSpaces]( '' ) 'Contains significant spaces'
select dbo.[AUX:HasSignificantSpaces]( null ) 'Contains significant spaces'
*/
--:SetVar Function "AUX:IsDigit"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IsDigit' )
   drop function [AUX:IsDigit]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IsDigit]( @Char nchar )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CHECKING, IF CHARACTER BELONGS TO DECIMAL DIGITS ('0','1',...'9'):
#
# === Usage: ===
# dbo.[AUX:IsDigit]( <Character> )
#
==================================================================================================*/

return IIF( CHARINDEX( @Char, '0123456789' ) > 0, 1, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IsDigit]( '5' ) 'Is digit'
select dbo.[AUX:IsDigit]( '0' ) 'Is digit'
select dbo.[AUX:IsDigit]( N'^' ) 'Is digit'
*/
--:SetVar Function "AUX:LogicalSign.BigInt"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:LogicalSign.BigInt' )
   drop function [AUX:LogicalSign.BigInt]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:LogicalSign.BigInt]( @Number bigint )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOGICAL FLAG (1/0) OF “BIT” TYPE — FOR BIG INTEGER (ONE FOR SIGNIFICANT NOT NULL):
#
# === Usage: ===
# dbo.[AUX:LogicalSign.BigInt]( <Number> )
#
==================================================================================================*/

return IIF( @Number<>0, 1, 0 )

/*================================================================================================*/
END
GO
/*
:SetVar Number "74"
select dbo.[AUX:LogicalSign.BigInt]( $(Number) ) 'Logical flag for $(Number)'
select dbo.[AUX:LogicalSign.BigInt]( 0 ) 'Logical flag for 0'
select dbo.[AUX:LogicalSign.BigInt]( null ) 'Logical flag for null'
*/
--:SetVar Function "AUX:LogicalSign.DateTime"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:LogicalSign.DateTime' )
   drop function [AUX:LogicalSign.DateTime]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:LogicalSign.DateTime]( @DateTime datetime2 )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOGICAL FLAG (1/0) OF “DATETIME” TYPE (ONE FOR NOT NULL DATE-TIME VALUE):
#
# === Usage: ===
# dbo.[AUX:LogicalSign.DateTime]( <Number> )
#
==================================================================================================*/

return IIF( @DateTime is not null, 1, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:LogicalSign.DateTime]( GETDATE() ) 'Logical flag for current date-time'
select dbo.[AUX:LogicalSign.DateTime]( null ) 'Logical flag for null'
*/
--:SetVar Function "AUX:LogicalSign.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:LogicalSign.DecMoney' )
   drop function [AUX:LogicalSign.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:LogicalSign.DecMoney]( @Number decimal(19,4) )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOGICAL FLAG (1/0) OF “BIT” TYPE — ONE FOR SIGNIFICANT NOT NULL (“$(dt_DecMoney_AUX)”):
#
# === Usage: ===
# dbo.[AUX:LogicalSign.DecMoney]( <Number> )
#
==================================================================================================*/

return IIF( @Number<>0, 1, 0 )

/*================================================================================================*/
END
GO
/*
:SetVar Number "74.51"
select dbo.[AUX:LogicalSign.DecMoney]( $(Number) ) 'Logical flag for $(Number)'
select dbo.[AUX:LogicalSign.DecMoney]( 0 ) 'Logical flag for 0'
select dbo.[AUX:LogicalSign.DecMoney]( null ) 'Logical flag for null'
*/
--:SetVar Function "AUX:LogicalSign.DHP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:LogicalSign.DHP' )
   drop function [AUX:LogicalSign.DHP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:LogicalSign.DHP]( @Number decimal(38,16) )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOGICAL FLAG (1/0) OF “BIT” TYPE — ONE FOR SIGNIFICANT NOT NULL (“$(dt_HPDecimal_AUX)”):
#
# === Usage: ===
# dbo.[AUX:LogicalSign.DHP]( <Number> )
#
==================================================================================================*/

return IIF( @Number<>0, 1, 0 )

/*================================================================================================*/
END
GO
/*
:SetVar Number "74.5134"
select dbo.[AUX:LogicalSign.DHP]( $(Number) ) 'Logical flag for $(Number)'
select dbo.[AUX:LogicalSign.DHP]( 0 ) 'Logical flag for 0'
select dbo.[AUX:LogicalSign.DHP]( null ) 'Logical flag for null'
*/
--:SetVar Function "AUX:LogicalSign.DMP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:LogicalSign.DMP' )
   drop function [AUX:LogicalSign.DMP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:LogicalSign.DMP]( @Number decimal(28,10) )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOGICAL FLAG (1/0) OF “BIT” TYPE — ONE FOR SIGNIFICANT NOT NULL (“$(dt_MPDecimal_AUX)”):
#
# === Usage: ===
# dbo.[AUX:LogicalSign.DMP]( <Number> )
#
==================================================================================================*/

return IIF( @Number<>0, 1, 0 )

/*================================================================================================*/
END
GO
/*
:SetVar Number "74.5134"
select dbo.[AUX:LogicalSign.DMP]( $(Number) ) 'Logical flag for $(Number)'
select dbo.[AUX:LogicalSign.DMP]( 0 ) 'Logical flag for 0'
select dbo.[AUX:LogicalSign.DMP]( null ) 'Logical flag for null'
*/
--:SetVar Function "AUX:LogicalSign.Float"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:LogicalSign.Float' )
   drop function [AUX:LogicalSign.Float]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:LogicalSign.Float]( @Number float )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOGICAL FLAG (1/0) OF “BIT” TYPE — ONE FOR SIGNIFICANT NOT NULL (TYPE “FLOAT”):
#
# === Usage: ===
# dbo.[AUX:LogicalSign.Float]( <Number> )
#
==================================================================================================*/

return IIF( @Number<>0, 1, 0 )

/*================================================================================================*/
END
GO
/*
:SetVar Number "35135e-12"
select dbo.[AUX:LogicalSign.Float]( $(Number) ) 'Logical flag for $(Number)'
select dbo.[AUX:LogicalSign.Float]( 0 ) 'Logical flag for 0'
select dbo.[AUX:LogicalSign.Float]( null ) 'Logical flag for null'
*/
--:SetVar Function "AUX:LogicalSign.Int"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:LogicalSign.Int' )
   drop function [AUX:LogicalSign.Int]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:LogicalSign.Int]( @Number int )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOGICAL FLAG (1/0) OF “BIT” TYPE — FOR INTEGER NUMBER (ONE FOR SIGNIFICANT NOT NULL):
#
# === Usage: ===
# dbo.[AUX:LogicalSign.Int]( <Number> )
#
==================================================================================================*/

return IIF( @Number<>0, 1, 0 )

/*================================================================================================*/
END
GO
/*
:SetVar Number "74"
select dbo.[AUX:LogicalSign.Int]( $(Number) ) 'Logical flag for $(Number)'
select dbo.[AUX:LogicalSign.Int]( 0 ) 'Logical flag for 0'
select dbo.[AUX:LogicalSign.Int]( null ) 'Logical flag for null'
*/
--:SetVar Function "AUX:LogicalSign.Str"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:LogicalSign.Str' )
   drop function [AUX:LogicalSign.Str]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:LogicalSign.Str]( @String nvarchar(max) )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOGICAL FLAG (1/0) OF “BIT” TYPE — FOR STRING VALUE (ONE FOR NON-EMPTY STRING):
#
# === Usage: ===
# dbo.[AUX:LogicalSign.Str]( <String> )
#
==================================================================================================*/

return IIF( @String<>'', 1, 0 )

/*================================================================================================*/
END
GO
/*
:SetVar _Text_ "qwerty"
select dbo.[AUX:LogicalSign.Str]( 'N$(_Text_)' ) 'Logical flag for “$(_Text_)”'
select dbo.[AUX:LogicalSign.Str]( '' ) 'Logical flag for empty string'
select dbo.[AUX:LogicalSign.Str]( null ) 'Logical flag for null'
*/
--:SetVar Function "AUX:Maximum.BigInt"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:Maximum.BigInt' )
   drop function [AUX:Maximum.BigInt]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:Maximum.BigInt]( @Value_1 bigint, @Value_2 bigint )
returns bigint
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINATION OF MAXIMUM AMONG TWO VALUES;
# ARGUMENT TYPE — “BIGINT”:
#
# === Usage: ===
# dbo.[AUX:Maximum.BigInt]( <Value_1>, <Value_2> )
#
==================================================================================================*/

if @Value_1 is null or @Value_2 is null
   return null

return IIF( @Value_1 > @Value_2, @Value_1, @Value_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:Maximum.BigInt]( -8435, 49 ) 'Maximum'
*/
--:SetVar Function "AUX:Maximum.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:Maximum.DecMoney' )
   drop function [AUX:Maximum.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:Maximum.DecMoney]( @Value_1 decimal(19,4), @Value_2 decimal(19,4) )
returns decimal(19,4)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINATION OF MAXIMUM AMONG TWO VALUES;
# ARGUMENT TYPE — “$(dt_DecMoney_AUX)”:
#
# === Usage: ===
# dbo.[AUX:Maximum.DecMoney]( <Value_1>, <Value_2> )
#
==================================================================================================*/

if @Value_1 is null or @Value_2 is null
   return null

return IIF( @Value_1 > @Value_2, @Value_1, @Value_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:Maximum.DecMoney]( 135.84, -84.35453 ) 'Maximum'
*/
--:SetVar Function "AUX:Maximum.DHP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:Maximum.DHP' )
   drop function [AUX:Maximum.DHP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:Maximum.DHP]( @Value_1 decimal(38,16), @Value_2 decimal(38,16) )
returns decimal(38,16)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINATION OF MAXIMUM AMONG TWO VALUES;
# ARGUMENT TYPE — “$(dt_HPDecimal_AUX)”:
#
# === Usage: ===
# dbo.[AUX:Maximum.DHP]( <Value_1>, <Value_2> )
#
==================================================================================================*/

if @Value_1 is null or @Value_2 is null
   return null

return IIF( @Value_1 > @Value_2, @Value_1, @Value_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:Maximum.DHP]( 135.84, -84.35453 ) 'Maximum'
*/
--:SetVar Function "AUX:Maximum.DMP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:Maximum.DMP' )
   drop function [AUX:Maximum.DMP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:Maximum.DMP]( @Value_1 decimal(28,10), @Value_2 decimal(28,10) )
returns decimal(28,10)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINATION OF MAXIMUM AMONG TWO VALUES;
# ARGUMENT TYPE — “$(dt_MPDecimal_AUX)”:
#
# === Usage: ===
# dbo.[AUX:Maximum.DMP]( <Value_1>, <Value_2> )
#
==================================================================================================*/

if @Value_1 is null or @Value_2 is null
   return null

return IIF( @Value_1 > @Value_2, @Value_1, @Value_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:Maximum.DMP]( 135.84, -84.35453 ) 'Maximum'
*/
--:SetVar Function "AUX:Maximum.Float"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:Maximum.Float' )
   drop function [AUX:Maximum.Float]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:Maximum.Float]( @Value_1 float, @Value_2 float )
returns float
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINATION OF MAXIMUM AMONG TWO VALUES;
# ARGUMENT TYPE — “FLOAT”:
#
# === Usage: ===
# dbo.[AUX:Maximum.Float]( <Value_1>, <Value_2> )
#
==================================================================================================*/

if @Value_1 is null or @Value_2 is null
   return null

return IIF( @Value_1 > @Value_2, @Value_1, @Value_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:Maximum.Float]( 135.84, 5e3 ) 'Maximum'
*/
--:SetVar Function "AUX:Maximum.Int"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:Maximum.Int' )
   drop function [AUX:Maximum.Int]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:Maximum.Int]( @Value_1 int, @Value_2 int )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINATION OF MAXIMUM AMONG TWO VALUES;
# ARGUMENT TYPE — “INT”:
#
# === Usage: ===
# dbo.[AUX:Maximum.Int]( <Value_1>, <Value_2> )
#
==================================================================================================*/

if @Value_1 is null or @Value_2 is null
   return null

return IIF( @Value_1 > @Value_2, @Value_1, @Value_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:Maximum.Int]( -8435, 49 ) 'Maximum'
*/
--:SetVar Function "AUX:Minimum.BigInt"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:Minimum.BigInt' )
   drop function [AUX:Minimum.BigInt]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:Minimum.BigInt]( @Value_1 bigint, @Value_2 bigint )
returns bigint
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINATION OF MINIMUM AMONG TWO VALUES;
# ARGUMENT TYPE — “BIGINT”:
#
# === Usage: ===
# dbo.[AUX:Minimum.BigInt]( <Value_1>, <Value_2> )
#
==================================================================================================*/

if @Value_1 is null or @Value_2 is null
   return null

return IIF( @Value_1 < @Value_2, @Value_1, @Value_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:Minimum.BigInt]( -8435, 49 ) 'Minimum'
*/
--:SetVar Function "AUX:Minimum.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:Minimum.DecMoney' )
   drop function [AUX:Minimum.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:Minimum.DecMoney]( @Value_1 decimal(19,4), @Value_2 decimal(19,4) )
returns decimal(19,4)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINATION OF MINIMUM AMONG TWO VALUES;
# ARGUMENT TYPE — “$(dt_DecMoney_AUX)”:
#
# === Usage: ===
# dbo.[AUX:Minimum.DecMoney]( <Value_1>, <Value_2> )
#
==================================================================================================*/

if @Value_1 is null or @Value_2 is null
   return null

return IIF( @Value_1 < @Value_2, @Value_1, @Value_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:Minimum.DecMoney]( 135.84, -84.35453 ) 'Minimum'
*/
--:SetVar Function "AUX:Minimum.DHP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:Minimum.DHP' )
   drop function [AUX:Minimum.DHP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:Minimum.DHP]( @Value_1 decimal(38,16), @Value_2 decimal(38,16) )
returns decimal(38,16)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINATION OF MINIMUM AMONG TWO VALUES;
# ARGUMENT TYPE — “$(dt_HPDecimal_AUX)”:
#
# === Usage: ===
# dbo.[AUX:Minimum.DHP]( <Value_1>, <Value_2> )
#
==================================================================================================*/

if @Value_1 is null or @Value_2 is null
   return null

return IIF( @Value_1 < @Value_2, @Value_1, @Value_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:Minimum.DHP]( 135.84, -84.35453 ) 'Minimum'
*/
--:SetVar Function "AUX:Minimum.DMP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:Minimum.DMP' )
   drop function [AUX:Minimum.DMP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:Minimum.DMP]( @Value_1 decimal(28,10), @Value_2 decimal(28,10) )
returns decimal(28,10)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINATION OF MINIMUM AMONG TWO VALUES;
# ARGUMENT TYPE — “$(dt_MPDecimal_AUX)”:
#
# === Usage: ===
# dbo.[AUX:Minimum.DMP]( <Value_1>, <Value_2> )
#
==================================================================================================*/

if @Value_1 is null or @Value_2 is null
   return null

return IIF( @Value_1 < @Value_2, @Value_1, @Value_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:Minimum.DMP]( 135.84, -84.35453 ) 'Minimum'
*/
--:SetVar Function "AUX:Minimum.Float"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:Minimum.Float' )
   drop function [AUX:Minimum.Float]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:Minimum.Float]( @Value_1 float, @Value_2 float )
returns float
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINATION OF MINIMUM AMONG TWO VALUES;
# ARGUMENT TYPE — “FLOAT”:
#
# === Usage: ===
# dbo.[AUX:Minimum.Float]( <Value_1>, <Value_2> )
#
==================================================================================================*/

if @Value_1 is null or @Value_2 is null
   return null

return IIF( @Value_1 < @Value_2, @Value_1, @Value_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:Minimum.Float]( 135.84, 5e3 ) 'Minimum'
*/
--:SetVar Function "AUX:Minimum.Int"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:Minimum.Int' )
   drop function [AUX:Minimum.Int]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:Minimum.Int]( @Value_1 int, @Value_2 int )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINATION OF MINIMUM AMONG TWO VALUES;
# ARGUMENT TYPE — “INT”:
#
# === Usage: ===
# dbo.[AUX:Minimum.Int]( <Value_1>, <Value_2> )
#
==================================================================================================*/

if @Value_1 is null or @Value_2 is null
   return null

return IIF( @Value_1 < @Value_2, @Value_1, @Value_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:Minimum.Int]( -8435, 49 ) 'Minimum'
*/
--:SetVar Function "AUX:PadEnd"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:PadEnd' )
   drop function [AUX:PadEnd]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:PadEnd]( @String nvarchar(max), @WidthForPadding int )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# STRING COMPLEMENT FROM END (WITH SPACES):
#
# === Usage: ===
# dbo.[AUX:PadEnd]( <String>, <Width for padding> )
#
==================================================================================================*/

return dbo.[AUX:PadEnd.Ext]( @String, @WidthForPadding, null )

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:PadEnd]( N'string', 10 )+'”' 'Complemented string'
select '“'+dbo.[AUX:PadEnd]( N'string', 5 )+'”' 'Complemented string'
*/
--:SetVar Function "AUX:PadStart"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:PadStart' )
   drop function [AUX:PadStart]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:PadStart]( @String nvarchar(max), @WidthForPadding int )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# STRING COMPLEMENT FROM START (WITH SPACES):
#
# === Usage: ===
# dbo.[AUX:PadStart]( <String>, <Width for padding> )
#
==================================================================================================*/

return dbo.[AUX:PadStart.Ext]( @String, @WidthForPadding, null )

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:PadStart]( N'string', 10 )+'”' 'Complemented string'
select '“'+dbo.[AUX:PadStart]( N'string', 5 )+'”' 'Complemented string'
*/
--:SetVar Function "AUX:StartsFromSpace"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:StartsFromSpace' )
   drop function [AUX:StartsFromSpace]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:StartsFromSpace]( @String nvarchar(max) )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CHECKING, IF STRING STARTS FROM SPACE:
#
# === Usage: ===
# dbo.[AUX:StartsFromSpace]( <String> )
#
==================================================================================================*/

return dbo.[AUX:StartsFromSpace.Ext]( @String, default )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:StartsFromSpace]( N'qwerty' ) 'Starts from space'
select dbo.[AUX:StartsFromSpace]( N' qwerty' ) 'Starts from space'
select dbo.[AUX:StartsFromSpace]( ' ' ) 'Starts from space'
select dbo.[AUX:StartsFromSpace]( '' ) 'Starts from space'
select dbo.[AUX:StartsFromSpace]( null ) 'Starts from space'
*/
--:SetVar Function "AUX:ZeroLeftPadByWidthOfAbs"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ZeroLeftPadByWidthOfAbs' )
   drop function [AUX:ZeroLeftPadByWidthOfAbs]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ZeroLeftPadByWidthOfAbs]( @String nvarchar(max), @WidthWithoutHeadMinus int )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# STRING COMPLEMENT WITH ZERO, BY WIDTH OF ABSOLUTE VALUE (WITHOUT MINUS SIGN):
#
# === Usage: ===
# dbo.[AUX:ZeroLeftPadByWidthOfAbs]( <String>, <Width without head minus> )
#
==================================================================================================*/

if @String is null or @WidthWithoutHeadMinus is null
   return null

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

if SUBSTRING( @String, 1, 1 ) <> '-'
   return dbo.[AUX:PadStart.Ext]( @String, @WidthWithoutHeadMinus, '0' )

return '-' + dbo.[AUX:PadStart.Ext](
   SUBSTRING( @String, 2, dbo.[AUX:StrLength]( @String ) - 1 ),
   @WidthWithoutHeadMinus, '0' )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ZeroLeftPadByWidthOfAbs]( 345178.237, 15 ) 'Complement to 15 (width-of-abs.)'
select dbo.[AUX:ZeroLeftPadByWidthOfAbs]( -8435.542, 15 ) 'Complement to 15 (width-of-abs.)'
*/
--:SetVar Function "AUX:IntSign.Int"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IntSign.Int' )
   drop function [AUX:IntSign.Int]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IntSign.Int]( @Value int )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# INTEGER SIGN FOR VALUE (“INT” ARG.TYPE):
#
# === Usage: ===
# dbo.[AUX:IntSign.Int]( <Value> )
#
==================================================================================================*/

if @Value is null return null

return
   case
      when @Value > 0 then  1
      when @Value < 0 then -1
      else 0
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IntSign.Int]( 123 ) 'Integer sign'
select dbo.[AUX:IntSign.Int]( -123 ) 'Integer sign'
select dbo.[AUX:IntSign.Int]( 0 ) 'Integer sign'
select dbo.[AUX:IntSign.Int]( null ) 'Integer sign'
*/
--:SetVar Function "AUX:RoundDiv.Ext"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:RoundDiv.Ext' )
   drop function [AUX:RoundDiv.Ext]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:RoundDiv.Ext]( @Divident int, @Divider int, @ZeroDivisionResNull bit=0 )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# ROUND DIVISION OF TWO INTEGERS (EXT.VERSION):
#
# === Usage: ===
# dbo.[AUX:RoundDiv.Ext]( <Divident>, <Divider>, 0 )
# dbo.[AUX:RoundDiv.Ext]( <Divident>, <Divider>, 1 )
# dbo.[AUX:RoundDiv.Ext]( <Divident>, <Divider>, null )
# dbo.[AUX:RoundDiv.Ext]( <Divident>, <Divider>, default )
#
==================================================================================================*/

if @ZeroDivisionResNull is null
   set @ZeroDivisionResNull = 0

if @Divident is null or @Divider is null or
   @Divider = 0 and @ZeroDivisionResNull = 1
   return null
/*
return ROUND( CONVERT(float,@Divident) / @Divider, 0, 0 )
*/
declare @Div int
set @Div = @Divident / @Divider
return
   case
      when ABS( @Divident % @Divider * 2 ) >= ABS( @Divider )
      then ( ABS( @Div ) + 1 ) * dbo.[AUX:IntSign.Int]( @Divident ) * dbo.[AUX:IntSign.Int]( @Divider )
      else @Div
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:RoundDiv.Ext]( 10, 3, null ) 'Round division'
select dbo.[AUX:RoundDiv.Ext]( 14, 9, default ) 'Round division'
*/
/*
select dbo.[AUX:RoundDiv.Ext]( 7, 0, 0 ) 'Round division'
select dbo.[AUX:RoundDiv.Ext]( 7, 0, 1 ) 'Round division'
select dbo.[AUX:RoundDiv.Ext]( 7, 0, null ) 'Round division'
select dbo.[AUX:RoundDiv.Ext]( 7, 0, default ) 'Round division'
*/
--:SetVar Function "AUX:RoundDiv"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:RoundDiv' )
   drop function [AUX:RoundDiv]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:RoundDiv]( @Divident int, @Divider int )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# ROUND DIVISION (OF TWO INTEGERS):
#
# === Usage: ===
# dbo.[AUX:RoundDiv]( <Divident>, <Divider> )
#
==================================================================================================*/

return dbo.[AUX:RoundDiv.Ext]( @Divident, @Divider, default )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:RoundDiv]( 10, 3 ) 'Round division'
select dbo.[AUX:RoundDiv]( 14, 9 ) 'Round division'
*/
/*
select dbo.[AUX:RoundDiv]( 7, 0 ) 'Round division'
*/
--:SetVar Function "AUX:IntRound.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IntRound.DecMoney' )
   drop function [AUX:IntRound.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IntRound.DecMoney]( @Value decimal(19,4) )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# ROUNDING TO INTEGER (“$(dt_DecMoney_AUX)” ARG.TYPE):
#
# === Usage: ===
# dbo.[AUX:IntRound.DecMoney]( <Value> )
#
==================================================================================================*/

return ROUND( @Value, 0, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IntRound.DecMoney]( 543.007 ) 'Rounding to integer (dec.money)'
select dbo.[AUX:IntRound.DecMoney]( -94.05 ) 'Rounding to integer (dec.money)'
*/
--:SetVar Function "AUX:IntRound.DHP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IntRound.DHP' )
   drop function [AUX:IntRound.DHP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IntRound.DHP]( @Value decimal(38,16) )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# ROUNDING TO INTEGER (“$(dt_HPDecimal_AUX)” ARG.TYPE):
#
# === Usage: ===
# dbo.[AUX:IntRound.DHP]( <Value> )
#
==================================================================================================*/

return ROUND( @Value, 0, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IntRound.DHP]( 543.007 ) 'Rounding to integer (DHP)'
select dbo.[AUX:IntRound.DHP]( -94.05 ) 'Rounding to integer (DHP)'
*/
--:SetVar Function "AUX:IntRound.DMP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IntRound.DMP' )
   drop function [AUX:IntRound.DMP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IntRound.DMP]( @Value decimal(28,10) )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# ROUNDING TO INTEGER (“$(dt_MPDecimal_AUX)” ARG.TYPE):
#
# === Usage: ===
# dbo.[AUX:IntRound.DMP]( <Value> )
#
==================================================================================================*/

return ROUND( @Value, 0, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IntRound.DMP]( 543.007 ) 'Rounding to integer (DMP)'
select dbo.[AUX:IntRound.DMP]( -94.05 ) 'Rounding to integer (DMP)'
*/
--:SetVar Function "AUX:IntRound.Float"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IntRound.Float' )
   drop function [AUX:IntRound.Float]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IntRound.Float]( @Value float )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# ROUNDING TO INTEGER (“FLOAT” ARG.TYPE):
#
# === Usage: ===
# dbo.[AUX:IntRound.Float]( <Value> )
#
==================================================================================================*/

return ROUND( @Value, 0, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IntRound.Float]( 543.007 ) 'Rounding to integer (float)'
select dbo.[AUX:IntRound.Float]( -94.05 ) 'Rounding to integer (float)'
*/
--:SetVar Function "AUX:IntSign.BigInt"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IntSign.BigInt' )
   drop function [AUX:IntSign.BigInt]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IntSign.BigInt]( @Value bigint )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# INTEGER SIGN FOR VALUE (“BIGINT” ARG.TYPE):
#
# === Usage: ===
# dbo.[AUX:IntSign.BigInt]( <Value> )
#
==================================================================================================*/

if @Value is null return null

return
   case
      when @Value > 0 then  1
      when @Value < 0 then -1
      else 0
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IntSign.BigInt]( 123 ) 'Integer sign (bigint)'
select dbo.[AUX:IntSign.BigInt]( -123 ) 'Integer sign (bigint)'
select dbo.[AUX:IntSign.BigInt]( 0 ) 'Integer sign (bigint)'
select dbo.[AUX:IntSign.BigInt]( null ) 'Integer sign (bigint)'
*/
--:SetVar Function "AUX:IntSign.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IntSign.DecMoney' )
   drop function [AUX:IntSign.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IntSign.DecMoney]( @Value decimal(19,4) )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# INTEGER SIGN FOR VALUE (“$(dt_DecMoney_AUX)” ARG.TYPE):
#
# === Usage: ===
# dbo.[AUX:IntSign.DecMoney]( <Value> )
#
==================================================================================================*/

if @Value is null return null

return
   case
      when @Value > 0 then  1
      when @Value < 0 then -1
      else 0
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IntSign.DecMoney]( 123.567 ) 'Integer sign (dec.money)'
select dbo.[AUX:IntSign.DecMoney]( -123.567 ) 'Integer sign (dec.money)'
select dbo.[AUX:IntSign.DecMoney]( 0 ) 'Integer sign (dec.money)'
select dbo.[AUX:IntSign.DecMoney]( null ) 'Integer sign (dec.money)'
*/
--:SetVar Function "AUX:IntSign.DHP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IntSign.DHP' )
   drop function [AUX:IntSign.DHP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IntSign.DHP]( @Value decimal(38,16) )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# INTEGER SIGN FOR VALUE (“$(dt_HPDecimal_AUX)” ARG.TYPE):
#
# === Usage: ===
# dbo.[AUX:IntSign.DHP]( <Value> )
#
==================================================================================================*/

if @Value is null return null

return
   case
      when @Value > 0 then  1
      when @Value < 0 then -1
      else 0
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IntSign.DHP]( 123.567 ) 'Integer sign (DHP)'
select dbo.[AUX:IntSign.DHP]( -123.567 ) 'Integer sign (DHP)'
select dbo.[AUX:IntSign.DHP]( 0 ) 'Integer sign (DHP)'
select dbo.[AUX:IntSign.DHP]( null ) 'Integer sign (DHP)'
*/
--:SetVar Function "AUX:IntSign.DMP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IntSign.DMP' )
   drop function [AUX:IntSign.DMP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IntSign.DMP]( @Value decimal(28,10) )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# INTEGER SIGN FOR VALUE (“$(dt_MPDecimal_AUX)” ARG.TYPE):
#
# === Usage: ===
# dbo.[AUX:IntSign.DMP]( <Value> )
#
==================================================================================================*/

if @Value is null return null

return
   case
      when @Value > 0 then  1
      when @Value < 0 then -1
      else 0
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IntSign.DMP]( 123.567 ) 'Integer sign (DMP)'
select dbo.[AUX:IntSign.DMP]( -123.567 ) 'Integer sign (DMP)'
select dbo.[AUX:IntSign.DMP]( 0 ) 'Integer sign (DMP)'
select dbo.[AUX:IntSign.DMP]( null ) 'Integer sign (DMP)'
*/
--:SetVar Function "AUX:IntSign.Float"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IntSign.Float' )
   drop function [AUX:IntSign.Float]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IntSign.Float]( @Value float )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# INTEGER SIGN FOR VALUE (“FLOAT” ARG.TYPE):
#
# === Usage: ===
# dbo.[AUX:IntSign.Float]( <Value> )
#
==================================================================================================*/

if @Value is null return null

return
   case
      when @Value > 0 then  1
      when @Value < 0 then -1
      else 0
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IntSign.Float]( 123.567 ) 'Integer sign (float)'
select dbo.[AUX:IntSign.Float]( -123.567 ) 'Integer sign (float)'
select dbo.[AUX:IntSign.Float]( 0 ) 'Integer sign (float)'
select dbo.[AUX:IntSign.Float]( null ) 'Integer sign (float)'
*/
--:SetVar Function "AUX:NegativeOrZero.BigInt"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:NegativeOrZero.BigInt' )
   drop function [AUX:NegativeOrZero.BigInt]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:NegativeOrZero.BigInt]( @Value bigint )
returns bigint
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# UPPER LIMITATION WITH ZERO (“BIGINT” TYPE):
#
# === Usage: ===
# dbo.[AUX:NegativeOrZero.BigInt]( <Value> )
#
==================================================================================================*/

return dbo.[AUX:Minimum.BigInt]( @Value, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:NegativeOrZero.BigInt]( 8453 ) 'Negative or zero'
select dbo.[AUX:NegativeOrZero.BigInt]( -27 ) 'Negative or zero'
*/
--:SetVar Function "AUX:NegativeOrZero.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:NegativeOrZero.DecMoney' )
   drop function [AUX:NegativeOrZero.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:NegativeOrZero.DecMoney]( @Value decimal(19,4) )
returns decimal(19,4)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# UPPER LIMITATION WITH ZERO (“$(dt_DecMoney_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:NegativeOrZero.DecMoney]( <Value> )
#
==================================================================================================*/

return dbo.[AUX:Minimum.DecMoney]( @Value, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:NegativeOrZero.DecMoney]( 543.007 ) 'Negative or zero'
select dbo.[AUX:NegativeOrZero.DecMoney]( -94.05 ) 'Negative or zero'
*/
--:SetVar Function "AUX:NegativeOrZero.DHP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:NegativeOrZero.DHP' )
   drop function [AUX:NegativeOrZero.DHP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:NegativeOrZero.DHP]( @Value decimal(38,16) )
returns decimal(38,16)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# UPPER LIMITATION WITH ZERO (“$(dt_HPDecimal_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:NegativeOrZero.DHP]( <Value> )
#
==================================================================================================*/

return dbo.[AUX:Minimum.DHP]( @Value, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:NegativeOrZero.DHP]( 543.007 ) 'Negative or zero'
select dbo.[AUX:NegativeOrZero.DHP]( -94.05 ) 'Negative or zero'
*/
--:SetVar Function "AUX:NegativeOrZero.DMP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:NegativeOrZero.DMP' )
   drop function [AUX:NegativeOrZero.DMP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:NegativeOrZero.DMP]( @Value decimal(28,10) )
returns decimal(28,10)
BEGIN
/*================================================================================================*/
/* SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# UPPER LIMITATION WITH ZERO (“$(dt_MPDecimal_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:NegativeOrZero.DMP]( <Value> )
#
==================================================================================================*/

return dbo.[AUX:Minimum.DMP]( @Value, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:NegativeOrZero.DMP]( 543.007 ) 'Negative or zero'
select dbo.[AUX:NegativeOrZero.DMP]( -94.05 ) 'Negative or zero'
*/
--:SetVar Function "AUX:NegativeOrZero.Float"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:NegativeOrZero.Float' )
   drop function [AUX:NegativeOrZero.Float]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:NegativeOrZero.Float]( @Value float )
returns float
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# UPPER LIMITATION WITH ZERO (“FLOAT” TYPE):
#
# === Usage: ===
# dbo.[AUX:NegativeOrZero.Float]( <Value> )
#
==================================================================================================*/

return dbo.[AUX:Minimum.Float]( @Value, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:NegativeOrZero.Float]( 543.007 ) 'Negative or zero'
select dbo.[AUX:NegativeOrZero.Float]( -94.05 ) 'Negative or zero'
*/
--:SetVar Function "AUX:NegativeOrZero.Int"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:NegativeOrZero.Int' )
   drop function [AUX:NegativeOrZero.Int]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:NegativeOrZero.Int]( @Value int )
returns int
BEGIN
/*================================================================================================*/
/* SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# UPPER LIMITATION WITH ZERO (“INT” TYPE):
#
# === Usage: ===
# dbo.[AUX:NegativeOrZero.Int]( <Value> )
#
==================================================================================================*/

return dbo.[AUX:Minimum.Int]( @Value, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:NegativeOrZero.Int]( 8453 ) 'Negative or zero'
select dbo.[AUX:NegativeOrZero.Int]( -27 ) 'Negative or zero'
*/
--:SetVar Function "AUX:PositiveOrZero.BigInt"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:PositiveOrZero.BigInt' )
   drop function [AUX:PositiveOrZero.BigInt]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:PositiveOrZero.BigInt]( @Value bigint )
returns bigint
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOWER LIMITATION WITH ZERO (“BIGINT” TYPE):
#
# === Usage: ===
# dbo.[AUX:PositiveOrZero.BigInt]( <Value> )
#
==================================================================================================*/

return dbo.[AUX:Maximum.Int]( @Value, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:PositiveOrZero.BigInt]( 8453 ) 'Positive or zero'
select dbo.[AUX:PositiveOrZero.BigInt]( -27 ) 'Positive or zero'
*/
--:SetVar Function "AUX:PositiveOrZero.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:PositiveOrZero.DecMoney' )
   drop function [AUX:PositiveOrZero.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:PositiveOrZero.DecMoney]( @Value decimal(19,4) )
returns decimal(19,4)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOWER LIMITATION WITH ZERO (“$(dt_DecMoney_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:PositiveOrZero.DecMoney]( <Value> )
#
==================================================================================================*/

return dbo.[AUX:Maximum.DecMoney]( @Value, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:PositiveOrZero.DecMoney]( 543.007 ) 'Positive or zero'
select dbo.[AUX:PositiveOrZero.DecMoney]( -94.05 ) 'Positive or zero'
*/
--:SetVar Function "AUX:PositiveOrZero.DHP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:PositiveOrZero.DHP' )
   drop function [AUX:PositiveOrZero.DHP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:PositiveOrZero.DHP]( @Value decimal(38,16) )
returns decimal(38,16)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOWER LIMITATION WITH ZERO (“$(dt_HPDecimal_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:PositiveOrZero.DHP]( <Value> )
#
==================================================================================================*/

return dbo.[AUX:Maximum.DHP]( @Value, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:PositiveOrZero.DHP]( 543.007 ) 'Positive or zero'
select dbo.[AUX:PositiveOrZero.DHP]( -94.05 ) 'Positive or zero'
*/
--:SetVar Function "AUX:PositiveOrZero.DMP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:PositiveOrZero.DMP' )
   drop function [AUX:PositiveOrZero.DMP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:PositiveOrZero.DMP]( @Value decimal(28,10) )
returns decimal(28,10)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOWER LIMITATION WITH ZERO (“$(dt_MPDecimal_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:PositiveOrZero.DMP]( <Value> )
#
==================================================================================================*/

return dbo.[AUX:Maximum.DMP]( @Value, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:PositiveOrZero.DMP]( 543.007 ) 'Positive or zero'
select dbo.[AUX:PositiveOrZero.DMP]( -94.05 ) 'Positive or zero'
*/
--:SetVar Function "AUX:PositiveOrZero.Float"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:PositiveOrZero.Float' )
   drop function [AUX:PositiveOrZero.Float]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:PositiveOrZero.Float]( @Value float )
returns float
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOWER LIMITATION WITH ZERO (“FLOAT” TYPE):
#
# === Usage: ===
# dbo.[AUX:PositiveOrZero.Float]( <Value> )
#
==================================================================================================*/

return dbo.[AUX:Maximum.Float]( @Value, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:PositiveOrZero.Float]( 543.007 ) 'Positive or zero'
select dbo.[AUX:PositiveOrZero.Float]( -94.05 ) 'Positive or zero'
*/
--:SetVar Function "AUX:PositiveOrZero.Int"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:PositiveOrZero.Int' )
   drop function [AUX:PositiveOrZero.Int]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:PositiveOrZero.Int]( @Value int )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# LOWER LIMITATION WITH ZERO (“INT” TYPE):
#
# === Usage: ===
# dbo.[AUX:PositiveOrZero.Int]( <Value> )
#
==================================================================================================*/

return dbo.[AUX:Maximum.Int]( @Value, 0 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:PositiveOrZero.Int]( 8453 ) 'Positive or zero'
select dbo.[AUX:PositiveOrZero.Int]( -27 ) 'Positive or zero'
*/
--:SetVar Function "AUX:ToString.Date"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToString.Date' )
   drop function [AUX:ToString.Date]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToString.Date]( @Date datetime2 )
returns char(10)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONVERSION FROM DATE TO STRING:
# - “MM/DD/YYYY” (EN);
# - “DD.MM.YYYY” (RU)
#
# === Usage: ===
# dbo.[AUX:ToString.Date]( <Date> )
#
==================================================================================================*/

if @Date is null return null

return CONVERT( char(10), @Date, dbo.[AUX:DateFormat]() )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToString.Date]( GETDATE() ) 'Today date as string'
*/
--:SetVar Function "AUX:ToString.Time"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToString.Time' )
   drop function [AUX:ToString.Time]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToString.Time]( @Time datetime2 )
returns char(8)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONVERSION FROM TIME TO STRING:
# - “HH::MM::SS” (EN);
# - “HH::MM::SS” (RU)
#
# === Usage: ===
# dbo.[AUX:ToString.Time]( <Date-time> )
#
==================================================================================================*/

if @Time is null return null

return CONVERT( char(8), @Time, dbo.[AUX:TimeFormat]() )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToString.Time]( GETDATE() ) 'Current time as string'
*/
--:SetVar Function "AUX:ToString.DateTime"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToString.DateTime' )
   drop function [AUX:ToString.DateTime]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToString.DateTime]( @DateTime datetime2 )
returns nvarchar(50)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONVERSION FROM DATE-TIME TO STRING:
# - “MM/DD/YYYY HH::MM::SS” (EN);
# - “DD.MM.YYYY HH::MM::SS” (RU)
#
# === Usage: ===
# dbo.[AUX:ToString.DateTime]( <Date-time> )
#
==================================================================================================*/

if @DateTime is null return null

return
   dbo.[AUX:ToString.Date]( @DateTime )+' '+
   dbo.[AUX:ToString.Time]( @DateTime )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToString.DateTime]( GETDATE() ) 'Current date-time as string'
*/
--:SetVar Function "AUX:ToString.BigInt"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToString.BigInt' )
   drop function [AUX:ToString.BigInt]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
GO
create function [AUX:ToString.BigInt]( @Number bigint )
returns varchar(20)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING (“BIGINT” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToString.BigInt]( <Number> )
#
==================================================================================================*/

if @Number is null return null

return CONVERT( varchar(20), @Number )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToString.BigInt]( 9223372036854775807 ) 'Number as string (bitint)'
select dbo.[AUX:ToString.BigInt]( -9223372036854775808 ) 'Number as string (bitint)'
*/
--:SetVar Function "AUX:ToString.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToString.DecMoney' )
   drop function [AUX:ToString.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToString.DecMoney]( @Number decimal(19,4) )
returns varchar(21)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING (“$(dt_DecMoney_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToString.DecMoney]( <Number> )
#
==================================================================================================*/

if @Number is null return null

return CONVERT( varchar(21), @Number )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToString.DecMoney]( 345178.21354 ) 'Money as string'
select dbo.[AUX:ToString.DecMoney]( -8435 ) 'Money as string'
*/
--:SetVar Function "AUX:ToString.DHP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToString.DHP' )
   drop function [AUX:ToString.DHP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToString.DHP]( @Number decimal(38,16) )
returns varchar(40)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING (“$(dt_HPDecimal_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToString.DHP]( <Number> )
#
==================================================================================================*/

if @Number is null return null

return CONVERT( varchar(40), @Number )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToString.DHP]( 345178.21354 ) 'Number as string'
select dbo.[AUX:ToString.DHP]( -8435 ) 'Number as string'
*/
--:SetVar Function "AUX:ToString.DMP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToString.DMP' )
   drop function [AUX:ToString.DMP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToString.DMP]( @Number decimal(28,10) )
returns varchar(30)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING (“$(dt_MPDecimal_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToString.DMP]( <Number> )
#
==================================================================================================*/

if @Number is null return null

return CONVERT( varchar(30), @Number )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToString.DMP]( 345178.21354 ) 'Number as string'
select dbo.[AUX:ToString.DMP]( -8435 ) 'Number as string'
*/
--:SetVar Function "AUX:ToString.Int"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToString.Int' )
   drop function [AUX:ToString.Int]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
GO
create function [AUX:ToString.Int]( @Number int )
returns varchar(11)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING (“INT” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToString.Int]( <Number> )
#
==================================================================================================*/

if @Number is null return null

return CONVERT( varchar(11), @Number )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToString.Int]( 345178 ) 'Number as string'
select dbo.[AUX:ToString.Int]( -8435 ) 'Number as string'
*/
--:SetVar Function "AUX:ToString_2.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToString_2.DecMoney' )
   drop function [AUX:ToString_2.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToString_2.DecMoney]( @Number decimal(19,4) )
returns varchar(19)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# MONEY CONVERSION TO STRING (“$(dt_DecMoney_AUX)” TYPE) — WITH TWO-DIGIT DECIMAL FRACTION:
#
# === Usage: ===
# dbo.[AUX:ToString_2.DecMoney]( <Number> )
#
==================================================================================================*/

if @Number is null return null

return CONVERT( varchar(19), CONVERT(decimal(17,2),@Number) )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToString_2.DecMoney]( 345178.21354 ) 'Money as string'
select dbo.[AUX:ToString_2.DecMoney]( -8435 ) 'Money as string'
*/
--:SetVar Function "AUX:ToStringFS.BigInt"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToStringFS.BigInt' )
   drop function [AUX:ToStringFS.BigInt]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
GO
create function [AUX:ToStringFS.BigInt]( @Number bigint, @AbsValueWidthForZeroPadding int=null )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING, WITH FIXED PRECISION (“BIGINT” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToStringFS.BigInt]( <Number>, <Absolute value width for zero padding> )
# dbo.[AUX:ToStringFS.BigInt]( <Number>, null )
#
==================================================================================================*/

if @Number is null return null

return dbo.[AUX:ZeroLeftPadByWidthOfAbs](
   CONVERT( varchar(20), @Number ),
   ISNULL( @AbsValueWidthForZeroPadding, 20-1 ) )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToStringFS.BigInt]( 9223372036854775807, 25 ) 'Number as string (fixed prec.)'
select dbo.[AUX:ToStringFS.BigInt]( -9223372036854775808, 25 ) 'Number as string (fixed prec.)'
*/
--:SetVar Function "AUX:ToStringFS.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToStringFS.DecMoney' )
   drop function [AUX:ToStringFS.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToStringFS.DecMoney]( @Number decimal(19,4),
                               @AbsValueWidthForZeroPadding int = null )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING, WITH FIXED PRECISION (“$(dt_DecMoney_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToStringFS.DecMoney]( <Number>, <Absolute value width for zero padding> )
# dbo.[AUX:ToStringFS.DecMoney]( <Number>, null )
#
==================================================================================================*/

if @Number is null return null

return dbo.[AUX:ZeroLeftPadByWidthOfAbs](
   CONVERT( varchar(21), @Number ),
   ISNULL( @AbsValueWidthForZeroPadding, 21-1 ) )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToStringFS.DecMoney]( 345178.21354, 20 ) 'Money as string (fixed prec.)'
select dbo.[AUX:ToStringFS.DecMoney]( -8435, 20 ) 'Money as string (fixed prec.)'
*/
--:SetVar Function "AUX:ToStringFS.DHP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToStringFS.DHP' )
   drop function [AUX:ToStringFS.DHP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToStringFS.DHP]( @Number decimal(38,16),
                               @AbsValueWidthForZeroPadding int = null )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING, WITH FIXED PRECISION (“$(dt_HPDecimal_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToStringFS.DHP]( <Number>, <Absolute value width for zero padding> )
# dbo.[AUX:ToStringFS.DHP]( <Number>, null )
#
==================================================================================================*/

if @Number is null return null

return dbo.[AUX:ZeroLeftPadByWidthOfAbs](
   CONVERT( varchar(40), @Number ),
   ISNULL( @AbsValueWidthForZeroPadding, 40-1 ) )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToStringFS.DHP]( 345178.21354, 20 ) 'Number as string (fixed prec.)'
select dbo.[AUX:ToStringFS.DHP]( -8435, 20 ) 'Number as string (fixed prec.)'
*/
--:SetVar Function "AUX:ToStringFS.DMP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToStringFS.DMP' )
   drop function [AUX:ToStringFS.DMP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToStringFS.DMP]( @Number decimal(28,10),
                               @AbsValueWidthForZeroPadding int = null )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING, WITH FIXED PRECISION (“$(dt_MPDecimal_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToStringFS.DMP]( <Number>, <Absolute value width for zero padding> )
# dbo.[AUX:ToStringFS.DMP]( <Number>, null )
#
==================================================================================================*/

if @Number is null return null

return dbo.[AUX:ZeroLeftPadByWidthOfAbs](
   CONVERT( varchar(30), @Number ),
   ISNULL( @AbsValueWidthForZeroPadding, 30-1 ) )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToStringFS.DMP]( 345178.21354, 20 ) 'Number as string (fixed prec.)'
select dbo.[AUX:ToStringFS.DMP]( -8435, 20 ) 'Number as string (fixed prec.)'
*/
--:SetVar Function "AUX:ToStringFS.Int"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToStringFS.Int' )
   drop function [AUX:ToStringFS.Int]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
GO
create function [AUX:ToStringFS.Int]( @Number int, @AbsValueWidthForZeroPadding int=null )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING, WITH FIXED PRECISION (“INT” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToStringFS.Int]( <Number>, <Absolute value width for zero padding> )
# dbo.[AUX:ToStringFS.Int]( <Number>, null )
#
==================================================================================================*/

if @Number is null return null

return dbo.[AUX:ZeroLeftPadByWidthOfAbs](
   CONVERT( varchar(11), @Number ),
   ISNULL( @AbsValueWidthForZeroPadding, 11-1 ) )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToStringFS.Int]( 345178, 10 ) 'Number as string (fixed prec.)'
select dbo.[AUX:ToStringFS.Int]( -8435, 10 ) 'Number as string (fixed prec.)'
*/
--:SetVar Function "AUX:ToStringFS_2.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToStringFS_2.DecMoney' )
   drop function [AUX:ToStringFS_2.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToStringFS_2.DecMoney]( @Number decimal(19,4),
                               @AbsValueWidthForZeroPadding int = null )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING, WITH FIXED PRECISION (“$(dt_DecMoney_AUX)” TYPE) —
# WITH TWO-DIGIT DECIMAL FRACTION:
#
# === Usage: ===
# dbo.[AUX:ToStringFS_2.DecMoney]( <Number>, <Absolute value width for zero padding> )
# dbo.[AUX:ToStringFS_2.DecMoney]( <Number>, null )
#
==================================================================================================*/

if @Number is null return null

return dbo.[AUX:ZeroLeftPadByWidthOfAbs](
   CONVERT( decimal(17,2), CONVERT(varchar(19),@Number) ),
   ISNULL( @AbsValueWidthForZeroPadding, 19-1 ) )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToStringFS_2.DecMoney]( 345178.21354, 20 ) 'Money as string (fixed prec.)'
select dbo.[AUX:ToStringFS_2.DecMoney]( -8435, 20 ) 'Money as string (fixed prec.)'
*/
--:SetVar Function "AUX:ToStringVS.DHP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToStringVS.DHP' )
   drop function [AUX:ToStringVS.DHP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToStringVS.DHP]( @Number decimal(38,16) )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING, WITH VARIABLE PRECISION (“$(dt_HPDecimal_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToStringVS.DHP]( <Number> )
#
==================================================================================================*/

if @Number is null return null

declare @String varchar(max), @DotPos int
set @String = dbo.[AUX:ToString.DHP]( @Number )
set @DotPos = CHARINDEX( '.', @String )
if @DotPos <= 0 return null

declare @P int
set @P = dbo.[AUX:StrLength]( @String )
while @P > @DotPos and SUBSTRING( @String, @P, 1 )='0'
   set @P = @P - 1
if @P = @DotPos
   set @P = @P - 1
if @P = 0
   return null

return SUBSTRING( @String, 1, @P )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToStringVS.DHP]( 345178.21354 ) 'Number as string (variable prec.)'
select dbo.[AUX:ToStringVS.DHP]( 345178.2135400 ) 'Number as string (variable prec.)'
select dbo.[AUX:ToStringVS.DHP]( -8435.000 ) 'Number as string (variable prec.)'
select dbo.[AUX:ToStringVS.DHP]( -8435 ) 'Number as string (variable prec.)'
*/
--:SetVar Function "AUX:ToStringVS.DMP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToStringVS.DMP' )
   drop function [AUX:ToStringVS.DMP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToStringVS.DMP]( @Number decimal(28,10) )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING, WITH VARIABLE PRECISION (“$(dt_MPDecimal_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToStringVS.DMP]( <Number> )
#
==================================================================================================*/

if @Number is null return null

declare @String varchar(max), @DotPos int
set @String = dbo.[AUX:ToString.DMP]( @Number )
set @DotPos = CHARINDEX( '.', @String )
if @DotPos <= 0 return null

declare @P int
set @P = dbo.[AUX:StrLength]( @String )
while @P > @DotPos and SUBSTRING( @String, @P, 1 )='0'
   set @P = @P - 1
if @P = @DotPos
   set @P = @P - 1
if @P = 0
   return null

return SUBSTRING( @String, 1, @P )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToStringVS.DMP]( 345178.21354 ) 'Number as string (variable prec.)'
select dbo.[AUX:ToStringVS.DMP]( 345178.2135400 ) 'Number as string (variable prec.)'
select dbo.[AUX:ToStringVS.DMP]( -8435.000 ) 'Number as string (variable prec.)'
select dbo.[AUX:ToStringVS.DMP]( -8435 ) 'Number as string (variable prec.)'
*/
--:SetVar Function "AUX:FormatNumByWidth"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:FormatNumByWidth' )
   drop function [AUX:FormatNumByWidth]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:FormatNumByWidth]( @NumberAsString nvarchar(max),
                               @WidthForPadding int,
                               @ExpressiveDisplayNull bit = 0 )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER FORMATTING BY WIDTH (WITH NUMBER ARGUMENT AS STRING):
# - LEFT COMPLEMENT WITH SPACES;
# - DENOTION OUT OF SPACE CHARACTERS AS “*”;
# - POSSIBLE DISPLAYING NULL-S AS REPLICATION OF “-” CHAR
#
# === Usage: ===
# dbo.[AUX:FormatNumByWidth]( <Number as string>,
#                             <Width for padding>,
#                             <Display null expressively> )
# dbo.[AUX:FormatNumByWidth]( <Number as string>, <Width for padding>, 0 )
# dbo.[AUX:FormatNumByWidth]( <Number as string>, <Width for padding>, 1 )
# dbo.[AUX:FormatNumByWidth]( <Number as string>, <Width for padding>, null )
# dbo.[AUX:FormatNumByWidth]( <Number as string>, <Width for padding>, default )
#
==================================================================================================*/

if @WidthForPadding is null or @WidthForPadding < 0
   return null
if @WidthForPadding = 0
   return ''

if @NumberAsString is null
   if @ExpressiveDisplayNull is not null
      return REPLICATE
      (
         case @ExpressiveDisplayNull
            when 1 then '-'
            else ' '
         end,
         @WidthForPadding
      )
   else
      return null

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

declare @String nvarchar(max), @Length int
set @String = dbo.[AUX:PadStart](
   TRIM( @NumberAsString ),
   @WidthForPadding )
set @Length = LEN( @String )

return
   case
      when @Length <= @WidthForPadding then @String
      else '*' +
         case
            when @WidthForPadding > 1
            then SUBSTRING( @String, @Length-@WidthForPadding+2, @WidthForPadding-1 )
            else ''
         end
   end

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:FormatNumByWidth]( '123456789', 10, default )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatNumByWidth]( '123456789', 5, default )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatNumByWidth]( '', 5, default )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatNumByWidth]( null, 5, default )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatNumByWidth]( null, 5, null )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatNumByWidth]( null, 5, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatNumByWidth]( null, 5, 1 )+'”' 'Number as string by width'
*/
--:SetVar Function "AUX:FormatByWidth.BigInt"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:FormatByWidth.BigInt' )
   drop function [AUX:FormatByWidth.BigInt]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
GO
create function [AUX:FormatByWidth.BigInt]( @Number bigint,
                               @WidthForPadding int = null,
                               @ExpressiveDisplayNull bit = 0 )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER FORMATTING BY WIDTH (“BIGINT” TYPE):
# - LEFT COMPLEMENT WITH SPACES;
# - DENOTION OUT OF SPACE CHARACTERS AS “*”;
# - POSSIBLE DISPLAYING NULL-S AS REPLICATION OF “-” CHAR
#
# === Usage: ===
# dbo.[AUX:FormatByWidth.BigInt]( <Number>, <Width for padding>, <Display null expressively> )
# dbo.[AUX:FormatByWidth.BigInt]( <Number>, <Width for padding>, 0 )
# dbo.[AUX:FormatByWidth.BigInt]( <Number>, <Width for padding>, 1 )
# dbo.[AUX:FormatByWidth.BigInt]( <Number>, <Width for padding>, default )
# dbo.[AUX:FormatByWidth.BigInt]( <Number>, null, 0 )
# dbo.[AUX:FormatByWidth.BigInt]( <Number>, null, 1 )
# dbo.[AUX:FormatByWidth.BigInt]( <Number>, null, default )
#
==================================================================================================*/

return dbo.[AUX:FormatNumByWidth]( dbo.[AUX:ToString.BigInt]( @Number ),
   ISNULL( @WidthForPadding, 20 ),
   @ExpressiveDisplayNull )

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:FormatByWidth.BigInt]( 9223372036854775807, 7, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.BigInt]( -9223372036854775808, 3, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.BigInt]( 9223372036854775807, null, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.BigInt]( null, 5, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.BigInt]( null, 5, 1 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.BigInt]( null, 5, default )+'”' 'Number as string by width'
*/
--:SetVar Function "AUX:FormatByWidth.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:FormatByWidth.DecMoney' )
   drop function [AUX:FormatByWidth.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
GO
create function [AUX:FormatByWidth.DecMoney]( @Number decimal(19,4),
                               @WidthForPadding int = null,
                               @ExpressiveDisplayNull bit = 0 )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER FORMATTING BY WIDTH (“$(dt_DecMoney_AUX)” TYPE):
# - LEFT COMPLEMENT WITH SPACES;
# - DENOTION OUT OF SPACE CHARACTERS AS “*”;
# - POSSIBLE DISPLAYING NULL-S AS REPLICATION OF “-” CHAR
#
# === Usage: ===
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, <Width for padding>, <Display null expressively> )
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, <Width for padding>, 0 )
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, <Width for padding>, 1 )
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, <Width for padding>, default )
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, null, 0 )
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, null, 1 )
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, null, default )
#
==================================================================================================*/

return dbo.[AUX:FormatNumByWidth]( dbo.[AUX:ToString.DecMoney]( @Number ),
   ISNULL( @WidthForPadding, 21 ),
   @ExpressiveDisplayNull )

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:FormatByWidth.DecMoney]( 345178.21354, 7, 0 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth.DecMoney]( -8435, 3, 0 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth.DecMoney]( 345178.21354, null, 0 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth.DecMoney]( null, 5, 0 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth.DecMoney]( null, 5, 1 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth.DecMoney]( null, 5, default )+'”' 'Money as string by width'
*/
--:SetVar Function "AUX:FormatByWidth.DHP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:FormatByWidth.DHP' )
   drop function [AUX:FormatByWidth.DHP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
GO
create function [AUX:FormatByWidth.DHP]( @Number decimal(38,16),
                               @WidthForPadding int = null,
                               @ExpressiveDisplayNull bit = 0 )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER FORMATTING BY WIDTH (“$(dt_HPDecimal_AUX)” TYPE):
# - LEFT COMPLEMENT WITH SPACES;
# - DENOTION OUT OF SPACE CHARACTERS AS “*”;
# - POSSIBLE DISPLAYING NULL-S AS REPLICATION OF “-” CHAR
#
# === Usage: ===
# dbo.[AUX:FormatByWidth.DHP]( <Number>, <Width for padding>, <Display null expressively> )
# dbo.[AUX:FormatByWidth.DHP]( <Number>, <Width for padding>, 0 )
# dbo.[AUX:FormatByWidth.DHP]( <Number>, <Width for padding>, 1 )
# dbo.[AUX:FormatByWidth.DHP]( <Number>, <Width for padding>, default )
# dbo.[AUX:FormatByWidth.DHP]( <Number>, null, 0 )
# dbo.[AUX:FormatByWidth.DHP]( <Number>, null, 1 )
# dbo.[AUX:FormatByWidth.DHP]( <Number>, null, default )
#
==================================================================================================*/

return dbo.[AUX:FormatNumByWidth]( dbo.[AUX:ToString.DHP]( @Number ),
   ISNULL( @WidthForPadding, 40 ),
   @ExpressiveDisplayNull )

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:FormatByWidth.DHP]( 345178.21354, 7, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.DHP]( -8435, 3, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.DHP]( 345178.21354, null, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.DHP]( null, 5, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.DHP]( null, 5, 1 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.DHP]( null, 5, default )+'”' 'Number as string by width'
*/
--:SetVar Function "AUX:FormatByWidth.DMP"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:FormatByWidth.DMP' )
   drop function [AUX:FormatByWidth.DMP]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
GO
create function [AUX:FormatByWidth.DMP]( @Number decimal(28,10),
                               @WidthForPadding int = null,
                               @ExpressiveDisplayNull bit = 0 )
returns varchar(max)
BEGIN
/*================================================================================================*/
/* SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER FORMATTING BY WIDTH (“$(dt_MPDecimal_AUX)” TYPE):
# - LEFT COMPLEMENT WITH SPACES;
# - DENOTION OUT OF SPACE CHARACTERS AS “*”;
# - POSSIBLE DISPLAYING NULL-S AS REPLICATION OF “-” CHAR
#
# === Usage: ===
# dbo.[AUX:FormatByWidth.DMP]( <Number>, <Width for padding>, <Display null expressively> )
# dbo.[AUX:FormatByWidth.DMP]( <Number>, <Width for padding>, 0 )
# dbo.[AUX:FormatByWidth.DMP]( <Number>, <Width for padding>, 1 )
# dbo.[AUX:FormatByWidth.DMP]( <Number>, <Width for padding>, default )
# dbo.[AUX:FormatByWidth.DMP]( <Number>, null, 0 )
# dbo.[AUX:FormatByWidth.DMP]( <Number>, null, 1 )
# dbo.[AUX:FormatByWidth.DMP]( <Number>, null, default )
*/
/*================================================================================================*/

return dbo.[AUX:FormatNumByWidth]( dbo.[AUX:ToString.DMP]( @Number ),
   ISNULL( @WidthForPadding, 30 ),
   @ExpressiveDisplayNull )

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:FormatByWidth.DMP]( 345178.21354, 7, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.DMP]( -8435, 3, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.DMP]( 345178.21354, null, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.DMP]( null, 5, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.DMP]( null, 5, 1 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.DMP]( null, 5, default )+'”' 'Number as string by width'
*/
--:SetVar Function "AUX:FormatByWidth.Int"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:FormatByWidth.Int' )
   drop function [AUX:FormatByWidth.Int]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
GO
create function [AUX:FormatByWidth.Int]( @Number int,
                               @WidthForPadding int = null,
                               @ExpressiveDisplayNull bit = 0 )
returns varchar(max)
BEGIN
/*================================================================================================*/
/* SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER FORMATTING BY WIDTH (“INT” TYPE):
# - LEFT COMPLEMENT WITH SPACES;
# - DENOTION OUT OF SPACE CHARACTERS AS “*”;
# - POSSIBLE DISPLAYING NULL-S AS REPLICATION OF “-” CHAR
#
# === Usage: ===
# dbo.[AUX:FormatByWidth.Int]( <Number>, <Width for padding>, <Display null expressively> )
# dbo.[AUX:FormatByWidth.Int]( <Number>, <Width for padding>, 0 )
# dbo.[AUX:FormatByWidth.Int]( <Number>, <Width for padding>, 1 )
# dbo.[AUX:FormatByWidth.Int]( <Number>, <Width for padding>, default )
# dbo.[AUX:FormatByWidth.Int]( <Number>, null, 0 )
# dbo.[AUX:FormatByWidth.Int]( <Number>, null, 1 )
# dbo.[AUX:FormatByWidth.Int]( <Number>, null, default )
*/
/*================================================================================================*/

return dbo.[AUX:FormatNumByWidth]( dbo.[AUX:ToString.Int]( @Number ),
   ISNULL( @WidthForPadding, 11 ),
   @ExpressiveDisplayNull )

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:FormatByWidth.Int]( 345178, 7, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.Int]( -8435, 3, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.Int]( 345178, null, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.Int]( null, 5, 0 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.Int]( null, 5, 1 )+'”' 'Number as string by width'
select '“'+dbo.[AUX:FormatByWidth.Int]( null, 5, default )+'”' 'Number as string by width'
*/
--:SetVar Function "AUX:FormatByWidth_2.DecMoney"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:FormatByWidth_2.DecMoney' )
   drop function [AUX:FormatByWidth_2.DecMoney]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
GO
create function [AUX:FormatByWidth_2.DecMoney]( @Number decimal(19,4),
                               @WidthForPadding int = null,
                               @ExpressiveDisplayNull bit = 0 )
returns varchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER FORMATTING BY WIDTH (“$(dt_DecMoney_AUX)” TYPE), WITH TWO-DIGIT DECIMAL FRACTION:
# - LEFT COMPLEMENT WITH SPACES;
# - DENOTION OUT OF SPACE CHARACTERS AS “*”;
# - POSSIBLE DISPLAYING NULL-S AS REPLICATION OF “-” CHAR
#
# === Usage: ===
# dbo.[AUX:FormatByWidth_2.DecMoney]( <Number>, <Width for padding>, <Display null expressively> )
# dbo.[AUX:FormatByWidth_2.DecMoney]( <Number>, <Width for padding>, 0 )
# dbo.[AUX:FormatByWidth_2.DecMoney]( <Number>, <Width for padding>, 1 )
# dbo.[AUX:FormatByWidth_2.DecMoney]( <Number>, <Width for padding>, default )
# dbo.[AUX:FormatByWidth_2.DecMoney]( <Number>, null, 0 )
# dbo.[AUX:FormatByWidth_2.DecMoney]( <Number>, null, 1 )
# dbo.[AUX:FormatByWidth_2.DecMoney]( <Number>, null, default )
#
==================================================================================================*/

return dbo.[AUX:FormatNumByWidth]( dbo.[AUX:ToString_2.DecMoney]( @Number ),
   ISNULL( @WidthForPadding, 21 ),
   @ExpressiveDisplayNull )

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:FormatByWidth_2.DecMoney]( 345178.21354, 7, 0 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth_2.DecMoney]( -8435, 3, 0 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth_2.DecMoney]( 345178.21354, null, 0 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth_2.DecMoney]( null, 5, 0 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth_2.DecMoney]( null, 5, 1 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth_2.DecMoney]( null, 5, default )+'”' 'Money as string by width'
*/
--:SetVar Function "AUX:MonthList"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:MonthList' )
   drop function [AUX:MonthList]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:MonthList]()
returns @ResultTable table
(
   [NO]              int                  not null,
   [Name]            nvarchar(15)  not null,
   [InGenitiveCase]  nvarchar(15)
)
AS
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# MONTH LIST WITH NUMBERS AND LOCALIZED NAMES (TABLE FUNCTION):
#
# === Usage: ===
# select * from [AUX:MonthList]()
#
==================================================================================================*/
declare @LanguageId int
set @LanguageId = dbo.[AUX:ActiveLanguage]()
if @LanguageId=0 goto IN_ENGLISH
if @LanguageId=21 goto IN_RUSSIAN
--if @LanguageId=-1 goto IN_XLANG_1
--if @LanguageId=-2 goto IN_XLANG_2
goto IN_ENGLISH
----------------------------------------------------------------------------------------------------
IN_ENGLISH:
insert @ResultTable
   select [NO], [Name], null 'InGenitiveCase'
   from [AUX::Month_list:En] (nolock)
   order by [NO]
return
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IN_RUSSIAN:
insert @ResultTable
   select [NO], [Name], [InGenitiveCase]
   from [AUX::Month_list:Ru] (nolock)
   order by [NO]
return
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*
IN_XLANG_1:
insert @ResultTable
   select [NO], [Name], null 'InGenitiveCase'
   from [AUX::Month_list:] (nolock)
   order by [NO]
return
*/
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*
IN_XLANG_2:
insert @ResultTable
   select [NO], [Name], null 'InGenitiveCase'
   from [AUX::Month_list:] (nolock)
   order by [NO]
return
*/
/*================================================================================================*/
END
GO
/*
select * from [AUX:MonthList]()
*/
--:SetVar Function "AUX:MonthName.Ext"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:MonthName.Ext' )
   drop function [AUX:MonthName.Ext]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:MonthName.Ext]( @Month int, @Options bit=0 )
returns nvarchar(15)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# OBTAINING LOCALIZED MONTH NAME BY ITS NUMBER (EXT.VERSION):
#
# === @Options: ===
# $(opt_MonthName_InGenitiveCase_AUX) = 1
#
# === Usage: ===
# dbo.[AUX:MonthName.Ext]( <Month NO>, null )
# dbo.[AUX:MonthName.Ext]( <Month NO>, 0 )
# dbo.[AUX:MonthName.Ext]( <Month NO>, 1 )
#
==================================================================================================*/
if @Month is null return null
----------------------------------------------------------------------------------------------------
if @Options is null set @Options=0
----------------------------------------------------------------------------------------------------
return (
   select IIF( @Options & 1 <> 0,
               [InGenitiveCase], [Name] )
   from [AUX:MonthList]()
   where [NO] = @Month )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:MonthName.Ext]( 11, null ) 'Month name'
select dbo.[AUX:MonthName.Ext]( 11, 0 ) 'Month name'
select dbo.[AUX:MonthName.Ext]( 11, 1 ) 'Month name'
*/
--:SetVar Function "AUX:MonthName"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:MonthName' )
   drop function [AUX:MonthName]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:MonthName]( @Month int )
returns nvarchar(15)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# OBTAINING LOCALIZED MONTH NAME BY ITS NUMBER:
#
# === Usage: ===
# dbo.[AUX:MonthName]( <Month NO> )
*/
/*================================================================================================*/
if @Month is null return null
----------------------------------------------------------------------------------------------------
return dbo.[AUX:MonthName.Ext]( @Month, null )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:MonthName]( 5 ) 'Month name (#5)'
select dbo.[AUX:MonthName]( 12 ) 'Month name (#12)'
*/
--:SetVar Function "AUX:MonthNameWithYear.Ext"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:MonthNameWithYear.Ext' )
   drop function [AUX:MonthNameWithYear.Ext]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:MonthNameWithYear.Ext]( @Year int, @Month int,
                               @Options bit = 3 )
returns nvarchar(25)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# OBTAINING LOCALIZED MONTH NAME WITH YEAR, IN FOLLOWING FORM:
# - “<Month name> YYYY”    (EN);
# - “<Month name> YYYY г.” (RU)
# (EXTENDED VERSION)
#
# === @Options: ===
# $(opt_MonthNameWithYear_PostscriptWithYearSign_AUX) = 1
# $(opt_MonthNameWithYear_PostscriptThroughSpace_AUX) = 2
# $(opt_MonthNameWithYear_Default_AUX) = 3
#
# === Usage: ===
# dbo.[AUX:MonthNameWithYear.Ext]( <Year>, <Month NO>, 0 )
# dbo.[AUX:MonthNameWithYear.Ext]( <Year>, <Month NO>, 1 )
# dbo.[AUX:MonthNameWithYear.Ext]( <Year>, <Month NO>, 3 )
# dbo.[AUX:MonthNameWithYear.Ext]( <Year>, <Month NO>, null )
#
==================================================================================================*/
if @Year is null or @Month is null or
   @Month not between 1 and 12
   return null
----------------------------------------------------------------------------------------------------
if @Options is null set @Options=3
----------------------------------------------------------------------------------------------------
declare @LanguageId int
set @LanguageId = dbo.[AUX:ActiveLanguage]()
if @LanguageId=0 goto IN_ENGLISH
if @LanguageId=21 goto IN_RUSSIAN
--if @LanguageId=-1 goto IN_XLANG_1
--if @LanguageId=-2 goto IN_XLANG_2
goto IN_ENGLISH
----------------------------------------------------------------------------------------------------
IN_ENGLISH:
return
   dbo.[AUX:MonthName]( @Month )+' '+CONVERT( varchar(11), @Year )
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IN_RUSSIAN:
return
   dbo.[AUX:MonthName]( @Month )+' '+CONVERT( varchar(11), @Year ) +
   case
      when @Options & 1 <> 0 then
         case
            when @Options & 2 <> 0
            then N' г.'
            else N'г.'
         end
      else ''
   end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*
IN_XLANG_1:
return
   dbo.[AUX:MonthName]( @Month )+' '+...
*/
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*
IN_XLANG_2:
return
   dbo.[AUX:MonthName]( @Month )+' '+...
*/
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:MonthNameWithYear.Ext]( 2015, 10, 0 ) 'Month name with year'
select dbo.[AUX:MonthNameWithYear.Ext]( 2016, 10, 1 ) 'Month name with year'
select dbo.[AUX:MonthNameWithYear.Ext]( 2015, 10, null ) 'Month name with year'
*/
--:SetVar Function "AUX:MonthNameWithYear"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:MonthNameWithYear' )
   drop function [AUX:MonthNameWithYear]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:MonthNameWithYear]( @Year int, @Month int )
returns nvarchar(25)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# OBTAINING LOCALIZED MONTH NAME WITH YEAR, IN FOLLOWING FORM:
# - “<Month name> YYYY”    (EN);
# - “<Month name> YYYY г.” (RU)
#
# === Usage: ===
# dbo.[AUX:MonthNameWithYear]( <Year>, <Month NO> )
#
==================================================================================================*/

return dbo.[AUX:MonthNameWithYear.Ext]( @Year, @Month, null )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:MonthNameWithYear]( 2015, 3 ) 'Month name with year'
select dbo.[AUX:MonthNameWithYear]( 2016, 10 ) 'Month name with year'
*/
--:SetVar Function "AUX:WeekDayList"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:WeekDayList' )
   drop function [AUX:WeekDayList]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:WeekDayList]()
returns @ResultTable table
(
   [ID]           int                     not null,
   [NO]           int                     not null,
   [FromSundayNo] int                     not null,
   [FromMondayNo] int                     not null,
   [Name]         nvarchar(15)   not null
)
AS
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# WEEK DAYS WITH NUMBERS AND LOCALIZED NAMES (TABLE FUNCTION):
#
# === Usage: ===
# select * from [AUX:WeekDayList]()
#
==================================================================================================*/
declare @LanguageId int
set @LanguageId = dbo.[AUX:ActiveLanguage]()
if @LanguageId=0 goto IN_ENGLISH
if @LanguageId=21 goto IN_RUSSIAN
--if @LanguageId=-1 goto IN_XLANG_1
--if @LanguageId=-2 goto IN_XLANG_2
goto IN_ENGLISH
----------------------------------------------------------------------------------------------------
IN_ENGLISH:
insert @ResultTable
   select [ID], [FromSundayNo] 'NO', [FromSundayNo], [FromMondayNo], [Name]
   from [AUX::WeekDay_list:En] (nolock)
   order by [NO]
return
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IN_RUSSIAN:
insert @ResultTable
   select [ID], [FromMondayNo] 'NO', [FromSundayNo], [FromMondayNo], [Name]
   from [AUX::WeekDay_list:Ru] (nolock)
   order by [NO]
return
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*
IN_XLANG_1:
insert @ResultTable
   select [NO], [] 'NO', [FromSundayNo], [FromMondayNo], [Name]
   from [AUX::WeekDay_list:] (nolock)
   order by [NO]
return
*/
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*
IN_XLANG_2:
insert @ResultTable
   select [NO], [] 'NO', [FromSundayNo], [FromMondayNo], [Name]
   from [AUX::WeekDay_list:] (nolock)
   order by [NO]
return
*/
/*================================================================================================*/
END
GO
/*
select * from [AUX:WeekDayList]()
*/
--:SetVar Function "AUX:WeekDayName.Ext"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:WeekDayName.Ext' )
   drop function [AUX:WeekDayName.Ext]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:WeekDayName.Ext]( @WeekDayNo int, @Options int=0 )
returns nvarchar(15)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# OBTAINING LOCALIZED WEEK DAY NAME BY ITS NUMBER [1..7] (EXT.VERSION):
#
# === @Options: ===
# $(opt_MonthName_InGenitiveCase_AUX) = 1
#
# === Usage: ===
# dbo.[AUX:WeekDayName.Ext]( <Week-day NO>, null )
# dbo.[AUX:WeekDayName.Ext]( <Week-day NO>, 0 )
# dbo.[AUX:WeekDayName.Ext]( <Week-day NO>, 1 ) -- from Sunday
# dbo.[AUX:WeekDayName.Ext]( <Week-day NO>, 2 ) -- from Monday
#
==================================================================================================*/
if @WeekDayNo is null return null
----------------------------------------------------------------------------------------------------
if @Options is null set @Options=0
----------------------------------------------------------------------------------------------------

if @Options & 1 <> 0
   return ( select [Name] from [AUX:WeekDayList]() where [FromSundayNo] = @WeekDayNo )
if @Options & 2 <> 0
   return ( select [Name] from [AUX:WeekDayList]() where [FromMondayNo] = @WeekDayNo )

return ( select [Name] from [AUX:WeekDayList]() where [NO] = @WeekDayNo )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:WeekDayName.Ext]( 1, null ) 'Week day name (#1)'
select dbo.[AUX:WeekDayName.Ext]( 1, 0 ) 'Week day name (#1)'
select dbo.[AUX:WeekDayName.Ext]( 1, 1 ) 'Week day name (#1-from-Sunday)'
select dbo.[AUX:WeekDayName.Ext]( 1, 2 ) 'Week day name (#1-from-Monday)'
*/
--:SetVar Function "AUX:WeekDayName"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:WeekDayName' )
   drop function [AUX:WeekDayName]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:WeekDayName]( @WeekDayNo int )
returns nvarchar(15)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# OBTAINING LOCALIZED WEEK DAY NAME BY ITS NUMBER [1..7]:
#
# === Usage: ===
# dbo.[AUX:WeekDayName]( <Week-day NO> )
#
==================================================================================================*/
if @WeekDayNo is null return null
----------------------------------------------------------------------------------------------------
return dbo.[AUX:WeekDayName.Ext]( @WeekDayNo, null )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:WeekDayName]( 1 ) 'Week day name (#1)'
*/
--:SetVar Function "AUX:WeekDayNameById"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:WeekDayNameById' )
   drop function [AUX:WeekDayNameById]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:WeekDayNameById]( @WeekDayId int )
returns nvarchar(15)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# OBTAINING LOCALIZED WEEK DAY NAME BY ITS ID [0..6]:
#
# === Usage: ===
# dbo.[AUX:WeekDayNameById]( <Week-day ID> )
#
==================================================================================================*/
if @WeekDayId is null return null
----------------------------------------------------------------------------------------------------
return ( select [Name] from [AUX:WeekDayList]() where [ID] = @WeekDayId )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:WeekDayNameById]( 0 ) 'Week day name by ID (#0)'
*/
--:SetVar Function "AUX:DateValue.YMD"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:DateValue.YMD' )
   drop function [AUX:DateValue.YMD]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:DateValue.YMD]( @Year int, @Month int, @Day int )
returns datetime2
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# MAKING DATE FROM YEAR, MONTH AND DAY:
#
# === Usage: ===
# dbo.[AUX:DateValue.YMD]( <Year>, <Month>, <Day> )
#
==================================================================================================*/

if @Year is null or @Month is null or @Day is null or
   not( @Month between 1 and 12 and @Day between 1 and 31 )
   return null

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

return DATETIME2FROMPARTS( @Year, @Month, @Day, 0, 0, 0, 0, 0 )
/*
return CONVERT( datetime2,
   dbo.[AUX:ToStringFS.Int]( @Year , 4 )+
   dbo.[AUX:ToStringFS.Int]( @Month, 2 )+
   dbo.[AUX:ToStringFS.Int]( @Day  , 2 ),
   $(num_ISODateFormatWithCentury_AUX) )
*/
/*================================================================================================*/
END
GO
/*
declare @Now datetime2
set @Now = GETDATE()
select dbo.[AUX:DateValue.YMD]( YEAR(@Now), MONTH(@Now), DAY(@Now) ) 'Current date'
select dbo.[AUX:DateValue.YMD]( 2017, 06, 14 ) 'Date value'
select dbo.[AUX:DateValue.YMD]( 2017, 06, 31 ) 'Incorrect date (June 31st)'
*/
--:SetVar Function "AUX:DaysInMonth.ByDate"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:DaysInMonth.ByDate' )
   drop function [AUX:DaysInMonth.ByDate]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:DaysInMonth.ByDate]( @Date datetime2 )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINING NUMBER OF DAYS IN MONTH (BY DATE VALUE):
#
# === Usage: ===
# dbo.[AUX:DaysInMonth.ByDate]( <Date> )
#
==================================================================================================*/

if @Date is null return null

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

declare @AbsoluteMonthCount int -- from beginning of year 1900
set @AbsoluteMonthCount = DATEDIFF( MONTH, 0, @Date )

return DATEDIFF( DAY,
   DATEADD( MONTH, @AbsoluteMonthCount, 0 ),
   DATEADD( MONTH, @AbsoluteMonthCount + 1, 0 ))

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:DaysInMonth.ByDate]( GETDATE() ) 'Days in current month'
*/
--:SetVar Function "AUX:DaysInMonth"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:DaysInMonth' )
   drop function [AUX:DaysInMonth]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:DaysInMonth]( @Year int, @Month int )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DETERMINING NUMBER OF DAYS IN MONTH:
#
# === Usage: ===
# dbo.[AUX:DaysInMonth]( <Year>, <Month> )
#
==================================================================================================*/

if @Year is null or @Month is null or
   @Month not between 1 and 12
   return null

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

return dbo.[AUX:DaysInMonth.ByDate](
   dbo.[AUX:DateValue.YMD]( @Year, @Month, 1 ))

/*================================================================================================*/
END
GO
/*
declare @Now datetime2
set @Now = GETDATE()
select dbo.[AUX:DaysInMonth]( YEAR(@Now), MONTH(@Now) ) 'Days in current month'
*/
--:SetVar Function "AUX:DateAsString.Ext"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:DateAsString.Ext' )
   drop function [AUX:DateAsString.Ext]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:DateAsString.Ext]( @Date datetime2,
                               @Options bit = 3 )
returns nvarchar(50)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DATE AS STRING REPRESENTATION:
# - “MM/DD/YYYY”    (EN);
# - “DD.MM.YYYY г.” (RU)
# (EXTENDED VERSION)
#
# === @Options: ===
# $(opt_MonthNameWithYear_PostscriptWithYearSign_AUX) = 1
# $(opt_MonthNameWithYear_PostscriptThroughSpace_AUX) = 2
# $(opt_DateAsString_Default_AUX) = $(opt_MonthNameWithYear_Default_AUX) = 3
#
# === Usage: ===
# dbo.[AUX:DateAsString.Ext]( <Date>, null, null )
# dbo.[AUX:DateAsString.Ext]( <Date>, 1, null )
# dbo.[AUX:DateAsString.Ext]( <Date>, 1, 0 )
#
==================================================================================================*/
if @Date is null return null
----------------------------------------------------------------------------------------------------
if @Options is null set @Options=3
----------------------------------------------------------------------------------------------------
declare @LanguageId int
set @LanguageId = dbo.[AUX:ActiveLanguage]()
if @LanguageId=0 goto IN_ENGLISH
if @LanguageId=21 goto IN_RUSSIAN
--if @LanguageId=-1 goto IN_XLANG_1
--if @LanguageId=-2 goto IN_XLANG_2
goto IN_ENGLISH
----------------------------------------------------------------------------------------------------
IN_ENGLISH:
return
   dbo.[AUX:ToString.Date]( @Date )
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IN_RUSSIAN:
return
   dbo.[AUX:ToString.Date]( @Date ) +
   case
      when @Options & 2 <> 0
      then IIF( @Options & 2 <> 0,
                N' г.', N'г.' )
      else ''
   end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*
IN_XLANG_1:
return
   dbo.[AUX:ToString.Date]( @Date ) +
   ...
*/
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*
IN_XLANG_2:
return
   dbo.[AUX:ToString.Date]( @Date ) +
   ...
*/
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:DateAsString.Ext]( GETDATE(), 0 ) 'Current date as string'
select dbo.[AUX:DateAsString.Ext]( GETDATE(), 1 ) 'Current date as string'
select dbo.[AUX:DateAsString.Ext]( GETDATE(), 3 ) 'Current date as string'
select dbo.[AUX:DateAsString.Ext]( GETDATE(), null ) 'Current date as string'
*/
--:SetVar Function "AUX:DateAsString"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:DateAsString' )
   drop function [AUX:DateAsString]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:DateAsString]( @Date datetime2 )
returns nvarchar(50)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DATE AS STRING REPRESENTATION:
# - “MM/DD/YYYY”    (EN);
# - “DD.MM.YYYY г.” (RU)
#
# === Usage: ===
# dbo.[AUX:DateAsString]( <Date> )
#
==================================================================================================*/

return dbo.[AUX:DateAsString.Ext]( @Date, null )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:DateAsString]( GETDATE() ) 'Current date as string'
*/
--:SetVar Function "AUX:DateTimeAsString.Ext"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:DateTimeAsString.Ext' )
   drop function [AUX:DateTimeAsString.Ext]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:DateTimeAsString.Ext]( @DateTime datetime2,
                               @Options bit = 3 )
returns nvarchar(50)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DATE-TIME AS STRING REPRESENTATION:
# - “MM/DD/YYYY HH:MM:SS” (EN);
# - “DD.MM.YYYY HH:MM:SS” (RU)
# (EXTENDED VERSION)
#
# === @Options: ===
# $(opt_MonthNameWithYear_PostscriptWithYearSign_AUX) = 1
# $(opt_MonthNameWithYear_PostscriptThroughSpace_AUX) = 2
# $(opt_DateTimeAsString_Default_AUX) = $(opt_MonthNameWithYear_Default_AUX) = 3
#
# === Usage: ===
# dbo.[AUX:DateTimeAsString.Ext]( <Date-time>, null, null )
# dbo.[AUX:DateTimeAsString.Ext]( <Date-time>, 1, 0 )
# dbo.[AUX:DateTimeAsString.Ext]( <Date-time>, 0, 0 )
#
==================================================================================================*/

return
   dbo.[AUX:DateAsString.Ext]( @DateTime, @Options )+' '+
   dbo.[AUX:ToString.Time]( @DateTime )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:DateTimeAsString.Ext]( GETDATE(), 0 ) 'Current date-time as string'
select dbo.[AUX:DateTimeAsString.Ext]( GETDATE(), 1 ) 'Current date-time as string'
select dbo.[AUX:DateTimeAsString.Ext]( GETDATE(), 3 ) 'Current date-time as string'
select dbo.[AUX:DateTimeAsString.Ext]( GETDATE(), null ) 'Current date-time as string'
*/
--:SetVar Function "AUX:DateTimeAsString"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:DateTimeAsString' )
   drop function [AUX:DateTimeAsString]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:DateTimeAsString]( @DateTime datetime2 )
returns nvarchar(50)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DATE-TIME AS STRING REPRESENTATION:
# - “MM/DD/YYYY HH:MM:SS” (EN);
# - “DD.MM.YYYY HH:MM:SS” (RU)
#
# === Usage: ===
# dbo.[AUX:DateTimeAsString]( <Date-time> )
#
==================================================================================================*/

return dbo.[AUX:DateTimeAsString.Ext]( @DateTime, null )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:DateTimeAsString]( GETDATE() ) 'Current date-time as string'
*/
--:SetVar Function "AUX:PureDate"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:PureDate' )
   drop function [AUX:PureDate]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:PureDate]( @DateTime datetime2 )
returns datetime2
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# MAKING PURE DATE VALUE (ONLY DAY, MONTH AND YEAR PARTS):
#
# === Usage: ===
# dbo.[AUX:PureDate]( <Date-time> )
#
==================================================================================================*/

return dbo.[AUX:DateValue.YMD](
   YEAR ( @DateTime ),
   MONTH( @DateTime ),
   DAY  ( @DateTime ) )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:PureDate]( CONVERT(datetime2,'11/17/2015',101) ) 'Pure date value'
select dbo.[AUX:PureDate]( CONVERT(datetime2,'17.11.2015',104) ) 'Pure date value'
select dbo.[AUX:PureDate]( GETDATE() ) 'Pure date value'
*/
--:SetVar Function "AUX:IsPureDate"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IsPureDate' )
   drop function [AUX:IsPureDate]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IsPureDate]( @Date datetime2 )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CHECKING DATE-TIME, THAT IT HAS NOT SMALL COMPONENTS (LESSER THAN DAY PART) —
# ONLY DAY, MONTH AND YEAR PARTS ARE ADMISSIBLE:
#
# === Usage: ===
# dbo.[AUX:IsPureDate]( <Date> )
#
==================================================================================================*/
return
   case
      when @Date is not null and
           dbo.[AUX:PureDate]( @Date ) = @Date
      then 1 else 0
   end
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IsPureDate]( CONVERT(datetime2,'17.11.2015',104) ) 'Is pure date'
select dbo.[AUX:IsPureDate]( GETDATE() ) 'Is pure date'
*/
--:SetVar Function "AUX:YMComparison"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:YMComparison' )
   drop function [AUX:YMComparison]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:YMComparison]( @Year_1 int, @Month_1 int=null,
                               @Year_2 int, @Month_2 int=null )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# COMPARISON OF TWO YEAR-MONTHS:
#
# Comparison result
# :   -1 —— 1st year-month is lesser than 2nd year-month;
# :    1 —— 1st year-month is greater than 2nd year-month;
# :    0 —— 1st year-month is equal to 2nd year-month;
# : null —— correlation is undetermined (null arg(s) or incorrect YM)
#
# === Usage: ===
# dbo.[AUX:YMComparison]( <Year-1>, <Month-1>, <Year-2>, <Month-2> )
# dbo.[AUX:YMComparison]( <Year-1>, <Month-1>, <Year-2>, null )
# dbo.[AUX:YMComparison]( <Year-1>, null, <Year-2>, <Month-2> )
#
==================================================================================================*/

if @Year_1 is null or @Year_1<0 or
   @Year_2 is null or @Year_2<0 or
   @Month_1 not between 1 and 12 or
   @Month_2 not between 1 and 12
   return null

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

if @Year_1 < @Year_2 return -1
if @Year_1 > @Year_2 return  1

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

if @Month_1 is null or @Month_2 is null
   return null

return
   case
      when @Month_1 < @Month_2 then -1
      when @Month_1 > @Month_2 then  1
      else 0
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:YMComparison]( 2015,11, 2015,11   ) 'YM-comparison result'
select dbo.[AUX:YMComparison]( 2015,11, 2015,10   ) 'YM-comparison result'
select dbo.[AUX:YMComparison]( 2015,11, 2015,12   ) 'YM-comparison result'
select dbo.[AUX:YMComparison]( 2015,11, 2015,null ) 'YM-comparison result'
select dbo.[AUX:YMComparison]( 2015,11, 2016,null ) 'YM-comparison result'
*/
--:SetVar Function "AUX:YMComparison.ByDate"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:YMComparison.ByDate' )
   drop function [AUX:YMComparison.ByDate]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:YMComparison.ByDate]( @Date_1 datetime2,
                               @Year_2 int, @Month_2 int=null )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# COMPARISON OF TWO YEAR-MONTHS (WITH FIRST ARGUMENT OF “DATETIME” TYPE):
#
# Comparison result
# :   -1 —— 1st year-month is lesser than 2nd year-month;
# :    1 —— 1st year-month is greater than 2nd year-month;
# :    0 —— 1st year-month is equal to 2nd year-month;
# : null —— correlation is undetermined (null arg(s) or incorrect YM2)
#
# === Usage: ===
# dbo.[AUX:YMComparison.ByDate]( <Date-1>, <Year-2>, <Month-2> )
# dbo.[AUX:YMComparison.ByDate]( <Date-1>, <Year-2>, null )
#
==================================================================================================*/

if @Date_1 is null
   return null

return
   dbo.[AUX:YMComparison](
      YEAR(@Date_1), MONTH(@Date_1),
      @Year_2, @Month_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:YMComparison.ByDate]( CONVERT(datetime2,'11/01/2015',101), 2015,11   ) 'YM-comparison result'
select dbo.[AUX:YMComparison.ByDate]( CONVERT(datetime2,'11/01/2015',101), 2015,10   ) 'YM-comparison result'
select dbo.[AUX:YMComparison.ByDate]( CONVERT(datetime2,'11/01/2015',101), 2015,12   ) 'YM-comparison result'
select dbo.[AUX:YMComparison.ByDate]( CONVERT(datetime2,'11/01/2015',101), 2015,null ) 'YM-comparison result'
select dbo.[AUX:YMComparison.ByDate]( CONVERT(datetime2,'11/01/2015',101), 2016,null ) 'YM-comparison result'
*/
--:SetVar Function "AUX:CompareDate.YMD"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:CompareDate.YMD' )
   drop function [AUX:CompareDate.YMD]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:CompareDate.YMD]( @Date_1 datetime2,
                               @Year_2 int, @Month_2 int=null, @Day_2 int=null )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DATE COMPARISON, WITH ROUNDING TO “YMD” (VIA TRUNCATION OF TIME PARTS):
#
# Comparison result
# :   -1 —— 1st YMD is lesser than 2nd YMD;
# :    1 —— 1st YMD is greater than 2nd YMD;
# :    0 —— 1st YMD is equal to 2nd YMD;
# : null —— correlation is undetermined (null arg(s) or incorrect YMD2)
#
# === Usage: ===
# dbo.[AUX:CompareDate.YMD]( <Date-1>, <Year-2>, <Month-2>, <Day-2> )
# dbo.[AUX:CompareDate.YMD]( <Date-1>, <Year-2>, <Month-2>, null )
# dbo.[AUX:CompareDate.YMD]( <Date-1>, <Year-2>, null, null )
#
==================================================================================================*/

if @Date_1  is null or
   @Year_2   is null or @Year_2<0 or
   @Month_2 is not null and @Month_2 not between 1 and 12 or
   @Day_2  is not null and @Day_2  not between 1 and 31 or
   @Month_2 is null and @Day_2 is not null
   return null

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

declare @Year_1 int, @Month_1 int, @Day_1 int
select @Year_1=YEAR( @Date_1 ), @Month_1=MONTH( @Date_1 ), @Day_1=DAY( @Date_1 )

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

if @Year_1 < @Year_2 return -1
if @Year_1 > @Year_2 return  1

if @Month_2 is null return null
if @Month_1 < @Month_2 return -1
if @Month_1 > @Month_2 return  1

if @Day_2 is null return null
if @Day_1 < @Day_2 return -1
if @Day_1 > @Day_2 return  1

return 0

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:CompareDate.YMD](
   CONVERT(datetime2,'11/17/2015',101),
   2015, 11, 19 ) 'Date comparison result'
select dbo.[AUX:CompareDate.YMD](
   CONVERT(datetime2,'12/17/2015',101),
   2015, 11, 19 ) 'Date comparison result'
select dbo.[AUX:CompareDate.YMD](
   CONVERT(datetime2,'12/17/2015',101),
   2015, 12, null ) 'Date comparison result'
select dbo.[AUX:CompareDate.YMD](
   CONVERT(datetime2,'12/17/2015',101),
   2015, null, null ) 'Date comparison result'
select dbo.[AUX:CompareDate.YMD](
   CONVERT(datetime2,'12/17/2015',101),
   2014, null, null ) 'Date comparison result'
*/
--:SetVar Function "AUX:CompareDates"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:CompareDates' )
   drop function [AUX:CompareDates]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:CompareDates]( @Date_1 datetime2, @Date_2 datetime2 )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# DATE COMPARISON, WITH ROUNDING TO “YMD” (VIA TRUNCATION OF TIME PARTS):
#
# Comparison result
# :   -1 —— 1st YMD is lesser than 2nd YMD;
# :    1 —— 1st YMD is greater than 2nd YMD;
# :    0 —— 1st YMD is equal to 2nd YMD;
# : null —— correlation is undetermined (at least one argument is null)
#
# === Usage: ===
# dbo.[AUX:CompareDates]( <Date-1>, <Date-2> )
#
==================================================================================================*/

if @Date_1 is null or @Date_2 is null return null

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

if DAY  ( @Date_1 ) = DAY  ( @Date_2 ) and
   MONTH( @Date_1 ) = MONTH( @Date_2 ) and
   YEAR ( @Date_1 ) = YEAR ( @Date_2 )
   return 0

return
   case
      when @Date_1 < @Date_2
      then -1 else 1
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:CompareDates](
   CONVERT(datetime2,'11/17/2015',101),
   CONVERT(datetime2,'11/19/2015',101) ) 'Date comparison result'
*/
--:SetVar Function "AUX:ToRomanNumber.Ext"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToRomanNumber.Ext' )
   drop function [AUX:ToRomanNumber.Ext]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToRomanNumber.Ext]( @Number int, @FormatUnsupportedValue bit=1 )
returns varchar(8)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONVERSION TO ROMAN NUMBER INSCRIPTION (WORKING VALUES: 1..100):
# (EXTENDED VERSION)
#
# === Usage: ===
# dbo.[AUX:ToRomanNumber.Ext]( <Number>, 0 )
# dbo.[AUX:ToRomanNumber.Ext]( <Number>, 1 )
#
==================================================================================================*/

if @FormatUnsupportedValue is null
   return null

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

declare @Display varchar(8)
select @Display = [Display] from [AUX::Roman_numbers] (nolock) where [Number] = @Number

return ISNULL( @Display,
   case @FormatUnsupportedValue
      when 1 then '<'+CONVERT( varchar(8), @Number )+'>'
      else null
   end )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToRomanNumber.Ext]( 0, 0 ) 'Roman number inscription for 0'
select dbo.[AUX:ToRomanNumber.Ext]( 0, 1 ) 'Roman number inscription for 0'
select dbo.[AUX:ToRomanNumber.Ext]( 4, 0 ) 'Roman number inscription for 4'
select dbo.[AUX:ToRomanNumber.Ext]( 15, 0 ) 'Roman number inscription for 15'
select dbo.[AUX:ToRomanNumber.Ext]( 100, 0 ) 'Roman number inscription for 100'
select dbo.[AUX:ToRomanNumber.Ext]( 101, 0 ) 'Roman number inscription for 101'
select dbo.[AUX:ToRomanNumber.Ext]( 101, 1 ) 'Roman number inscription for 101'
*/
--:SetVar Function "AUX:ToRomanNumber"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToRomanNumber' )
   drop function [AUX:ToRomanNumber]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToRomanNumber]( @Number int )
returns varchar(8)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONVERSION TO ROMAN NUMBER INSCRIPTION (WORKING VALUES: 1..100):
#
# === Usage: ===
# dbo.[AUX:ToRomanNumber]( <Number> )
#
==================================================================================================*/

return dbo.[AUX:ToRomanNumber.Ext]( @Number, 1 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToRomanNumber]( 0 ) 'Roman number inscription for 0'
select dbo.[AUX:ToRomanNumber]( 4 ) 'Roman number inscription for 4'
select dbo.[AUX:ToRomanNumber]( 15 ) 'Roman number inscription for 15'
select dbo.[AUX:ToRomanNumber]( 100 ) 'Roman number inscription for 100'
select dbo.[AUX:ToRomanNumber]( 101 ) 'Roman number inscription for 101'
*/
--:SetVar Function "AUX:RomanNumbers"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:RomanNumbers' )
   drop function [AUX:RomanNumbers]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:RomanNumbers]()
returns @ResultTable table
(
   [Number]    int                     not null,
   [Display]   varchar(8)   not null
)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# ROMAN NUMBER LIST — [1...100] (TABLE FUNCTION):
#
# === Usage: ===
# select * from [AUX:RomanNumbers]()
#
==================================================================================================*/
insert @ResultTable
   select [Number], [Display]
   from [AUX::Roman_numbers] (nolock)
   order by [Number]
return
/*================================================================================================*/
END
GO
/*
select * from [AUX:RomanNumbers]()
*/
--:SetVar Function "AUX:ThroughSeparator"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ThroughSeparator' )
   drop function [AUX:ThroughSeparator]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ThroughSeparator]( @String_1 nvarchar(max),
                               @String_2 nvarchar(max),
                               @Separator nvarchar(max) = null )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONCATENATION OF TWO STRINGS THROUGH SEPARATOR (THROUGH COMMA BY DEFAULT):
#
# === Usage: ===
# dbo.[AUX:ThroughSeparator]( <String-1>, <String-2>, <Separator> )
#
==================================================================================================*/

select
   @String_1 = ISNULL(@String_1,''),
   @String_2 = ISNULL(@String_2,'')

return
   case
      when dbo.[AUX:StrLength]( @String_1 ) = 0 then @String_2
      when dbo.[AUX:StrLength]( @String_2 ) = 0 then @String_1
      else
         @String_1 + ISNULL(@Separator,',') + @String_2
   end

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ThroughSeparator]( N'1', N'2', null ) 'Through separator'
select dbo.[AUX:ThroughSeparator]( N'First', N'Second', '; ' ) 'Through separator'
*/
--:SetVar Function "AUX:ThroughComma"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ThroughComma' )
   drop function [AUX:ThroughComma]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ThroughComma]( @String_1 nvarchar(max),
                               @String_2 nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONCATENATION OF TWO STRINGS THROUGH COMMA:
#
# === Usage: ===
# dbo.[AUX:ThroughComma]( <String-1>, <String-2> )
#
==================================================================================================*/

return dbo.[AUX:ThroughSeparator]( @String_1, @String_2, ',' )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ThroughComma]( N'1', N'2' ) 'Through comma'
*/
--:SetVar Function "AUX:ThroughCommaAndSpace"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ThroughCommaAndSpace' )
   drop function [AUX:ThroughCommaAndSpace]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ThroughCommaAndSpace]( @String_1 nvarchar(max),
                               @String_2 nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONCATENATION OF TWO STRINGS THROUGH COMMA AND SPACE:
#
# === Usage: ===
# dbo.[AUX:ThroughCommaAndSpace]( <String-1>, <String-2> )
#
==================================================================================================*/

return dbo.[AUX:ThroughSeparator]( @String_1, @String_2, ', ' )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ThroughCommaAndSpace]( N'First', N'Second' ) 'Through comma and space'
*/
--:SetVar Function "AUX:ThroughComma_3"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ThroughComma_3' )
   drop function [AUX:ThroughComma_3]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ThroughComma_3]( @String_1 nvarchar(max),
                               @String_2 nvarchar(max),
                               @String_3 nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONCATENATION OF THREE STRINGS THROUGH COMMA:
#
# === Usage: ===
# dbo.[AUX:ThroughComma_3]( <String-1>, <String-2>, <String-3> )
#
==================================================================================================*/

return dbo.[AUX:ThroughComma](
   dbo.[AUX:ThroughComma]( @String_1, @String_2 ),
   @String_3 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ThroughComma_3]( N'1', N'2', N'3' ) 'Through comma'
*/
--:SetVar Function "AUX:ThroughComma_4"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ThroughComma_4' )
   drop function [AUX:ThroughComma_4]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ThroughComma_4]( @String_1 nvarchar(max),
                               @String_2 nvarchar(max),
                               @String_3 nvarchar(max),
                               @String_4 nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONCATENATION OF FOUR STRINGS THROUGH COMMA:
#
# === Usage: ===
# dbo.[AUX:ThroughComma_4]( <String-1>, <String-2>, <String-3>, <String-4> )
#
==================================================================================================*/

return dbo.[AUX:ThroughComma](
   dbo.[AUX:ThroughComma_3]( @String_1, @String_2, @String_3 ),
   @String_4 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ThroughComma_4]( N'1', N'2', N'3', N'4' ) 'Through comma'
*/
--:SetVar Function "AUX:ThroughComma_5"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ThroughComma_5' )
   drop function [AUX:ThroughComma_5]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ThroughComma_5]( @String_1 nvarchar(max),
                               @String_2 nvarchar(max),
                               @String_3 nvarchar(max),
                               @String_4 nvarchar(max),
                               @String_5 nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONCATENATION OF FIVE STRINGS THROUGH COMMA:
#
# === Usage: ===
# dbo.[AUX:ThroughComma_5]( <String-1>, <String-2>, <String-3>, <String-4>, <String-5> )
#
==================================================================================================*/

return dbo.[AUX:ThroughComma](
   dbo.[AUX:ThroughComma_4]( @String_1, @String_2, @String_3, @String_4 ),
   @String_5 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ThroughComma_5]( N'1', N'2', N'3', N'4', N'5' ) 'Through comma'
*/
--:SetVar Function "AUX:ThroughCommaAndSpace_3"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ThroughCommaAndSpace_3' )
   drop function [AUX:ThroughCommaAndSpace_3]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ThroughCommaAndSpace_3]( @String_1 nvarchar(max),
                               @String_2 nvarchar(max),
                               @String_3 nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONCATENATION OF THREE STRINGS THROUGH COMMA AND SPACE:
#
# === Usage: ===
# dbo.[AUX:ThroughCommaAndSpace_3]( <String-1>, <String-2>, <String-3> )
#
==================================================================================================*/

return dbo.[AUX:ThroughCommaAndSpace](
   dbo.[AUX:ThroughCommaAndSpace]( @String_1, @String_2 ),
   @String_3 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ThroughCommaAndSpace_3]( N'First', N'Second', N'Third' ) 'Through comma and space'
*/
--:SetVar Function "AUX:ThroughCommaAndSpace_4"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ThroughCommaAndSpace_4' )
   drop function [AUX:ThroughCommaAndSpace_4]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ThroughCommaAndSpace_4]( @String_1 nvarchar(max),
                               @String_2 nvarchar(max),
                               @String_3 nvarchar(max),
                               @String_4 nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONCATENATION OF FOUR STRINGS THROUGH COMMA AND SPACE:
#
# === Usage: ===
# dbo.[AUX:ThroughCommaAndSpace_4]( <String-1>, <String-2>, <String-3>, <String-4> )
#
==================================================================================================*/

return dbo.[AUX:ThroughCommaAndSpace](
   dbo.[AUX:ThroughCommaAndSpace_3]( @String_1, @String_2, @String_3 ),
   @String_4 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ThroughCommaAndSpace_4]( N'First', N'Second', N'Third', N'Fourth' ) 'Through comma and space'
*/
--:SetVar Function "AUX:ThroughCommaAndSpace_5"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ThroughCommaAndSpace_5' )
   drop function [AUX:ThroughCommaAndSpace_5]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ThroughCommaAndSpace_5]( @String_1 nvarchar(max),
                               @String_2 nvarchar(max),
                               @String_3 nvarchar(max),
                               @String_4 nvarchar(max),
                               @String_5 nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONCATENATION OF FIVE STRINGS THROUGH COMMA AND SPACE:
#
# === Usage: ===
# dbo.[AUX:ThroughCommaAndSpace_5]( <String-1>, <String-2>, <String-3>, <String-4>, <String-5> )
#
==================================================================================================*/

return dbo.[AUX:ThroughCommaAndSpace](
   dbo.[AUX:ThroughCommaAndSpace_4]( @String_1, @String_2, @String_3, @String_4 ),
   @String_5 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ThroughCommaAndSpace_5]( N'First', N'Second', N'Third', N'Fourth', N'Fifth' ) 'Through comma and space'
*/
--:SetVar Function "AUX:ThroughSeparator_3"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ThroughSeparator_3' )
   drop function [AUX:ThroughSeparator_3]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ThroughSeparator_3]( @Separator nvarchar(max) = null,
                               @String_1 nvarchar(max),
                               @String_2 nvarchar(max),
                               @String_3 nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONCATENATION OF THREE STRINGS THROUGH SEPARATOR (THROUGH COMMA BY DEFAULT):
#
# === Usage: ===
# dbo.[AUX:ThroughSeparator_3]( <Separator>, <String-1>, <String-2>, <String-3> )
#
==================================================================================================*/

return dbo.[AUX:ThroughSeparator](
   dbo.[AUX:ThroughSeparator]( @String_1, @String_2, @Separator ),
   @String_3, @Separator )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ThroughSeparator_3]( null, N'1', N'2', N'3' ) 'Through separator'
select dbo.[AUX:ThroughSeparator_3]( '; ', N'First', N'Second', N'Third' ) 'Through separator'
*/
--:SetVar Function "AUX:ThroughSeparator_4"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ThroughSeparator_4' )
   drop function [AUX:ThroughSeparator_4]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ThroughSeparator_4]( @Separator nvarchar(max) = null,
                               @String_1 nvarchar(max),
                               @String_2 nvarchar(max),
                               @String_3 nvarchar(max),
                               @String_4 nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONCATENATION OF FOUR STRINGS THROUGH SEPARATOR (THROUGH COMMA BY DEFAULT):
#
# === Usage: ===
# dbo.[AUX:ThroughSeparator_4]( <Separator>, <String-1>, <String-2>, <String-3>, <String-4> )
#
==================================================================================================*/

return dbo.[AUX:ThroughSeparator](
   dbo.[AUX:ThroughSeparator_3]( @Separator, @String_1, @String_2, @String_3 ),
   @String_4, @Separator )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ThroughSeparator_4]( null, N'1', N'2', N'3', N'4' ) 'Through separator'
select dbo.[AUX:ThroughSeparator_4]( '; ', N'First', N'Second', N'Third', N'Fourth' ) 'Through separator'
*/
--:SetVar Function "AUX:ThroughSeparator_5"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ThroughSeparator_5' )
   drop function [AUX:ThroughSeparator_5]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ThroughSeparator_5]( @Separator nvarchar(max) = null,
                               @String_1 nvarchar(max),
                               @String_2 nvarchar(max),
                               @String_3 nvarchar(max),
                               @String_4 nvarchar(max),
                               @String_5 nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONCATENATION OF FIVE STRINGS THROUGH SEPARATOR (THROUGH COMMA BY DEFAULT):
#
# === Usage: ===
# dbo.[AUX:ThroughSeparator_5]( <Separator>,
#                             <String-1>, <String-2>, <String-3>, <String-4>, <String-5> )
#
==================================================================================================*/

return dbo.[AUX:ThroughSeparator](
   dbo.[AUX:ThroughSeparator_4]( @Separator, @String_1, @String_2, @String_3, @String_4 ),
   @String_5, @Separator )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ThroughSeparator_5]( null, N'1', N'2', N'3', N'4', N'5' ) 'Through separator'
select dbo.[AUX:ThroughSeparator_5]( '; ', N'First', N'Second', N'Third', N'Fourth', N'Fifth' ) 'Through separator'
*/
--:SetVar Function "AUX:EmptyGUID"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:EmptyGUID' )
   drop function [AUX:EmptyGUID]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:EmptyGUID]()
returns uniqueidentifier
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# EMPTY GUID (NEUTRAL IDENTIFIER):
#
# === Usage: ===
# dbo.[AUX:EmptyGUID()]()
#
==================================================================================================*/
return '00000000-0000-0000-0000-000000000000'
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:EmptyGUID]() 'Empty GUID'
*/
--:SetVar Function "AUX:FormatGUID"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:FormatGUID' )
   drop function [AUX:FormatGUID]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:FormatGUID]( @Identifier uniqueidentifier )
returns char(38)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# GUID FORMATTING (CONVERSION TO STRING WITH BOUNDING CURLY BRACKETS):
#
# === Usage: ===
# dbo.[AUX:FormatGUID]( <Itendifier> )
#
==================================================================================================*/

if @Identifier is null
   return '{'+'???'+'}'

return '{'+CONVERT( char(36), @Identifier )+'}'

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:FormatGUID]( '5C2B43BB-5E3C-4E09-AC22-0CAFD0C6B830' ) 'GUID'
select dbo.[AUX:FormatGUID]( NEWID() ) 'GUID'
select dbo.[AUX:FormatGUID]( null ) 'GUID'
*/
--:SetVar Function "AUX:IsEmptyGUID"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IsEmptyGUID' )
   drop function [AUX:IsEmptyGUID]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IsEmptyGUID]( @Identifier uniqueidentifier )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CHECKING IF GUID IS EMPTY:
#
# === Usage: ===
# dbo.[AUX:IsEmptyGUID]( <Itendifier> )
#
==================================================================================================*/
return IIF( @Identifier = '00000000-0000-0000-0000-000000000000', 1, 0 )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IsEmptyGUID]( '5C2B43BB-5E3C-4E09-AC22-0CAFD0C6B830' ) 'Is GUID empty'
select dbo.[AUX:IsEmptyGUID]( NEWID() ) 'Is GUID empty'
select dbo.[AUX:IsEmptyGUID]( '00000000-0000-0000-0000-000000000000' ) 'Is GUID empty'
select dbo.[AUX:IsEmptyGUID]( null ) 'Is GUID empty'
*/
--:SetVar Function "AUX:IsSignificantGUID"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IsSignificantGUID' )
   drop function [AUX:IsSignificantGUID]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IsSignificantGUID]( @Identifier uniqueidentifier )
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CHECKING IF GUID IS SIGNIFICANT (NOT EMPTY):
#
# === Usage: ===
# dbo.[AUX:IsSignificantGUID]( <Itendifier> )
#
==================================================================================================*/
return IIF( @Identifier <> '00000000-0000-0000-0000-000000000000', 1, 0 )
/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IsSignificantGUID]( '5C2B43BB-5E3C-4E09-AC22-0CAFD0C6B830' ) 'Is GUID significant'
select dbo.[AUX:IsSignificantGUID]( NEWID() ) 'Is GUID significant'
select dbo.[AUX:IsSignificantGUID]( '00000000-0000-0000-0000-000000000000' ) 'Is GUID significant'
select dbo.[AUX:IsSignificantGUID]( null ) 'Is GUID significant'
*/
--:SetVar Function "AUX:IsInServerAdminRole"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:IsInServerAdminRole' )
   drop function [AUX:IsInServerAdminRole]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:IsInServerAdminRole]()
returns bit
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CHECKING, IF CONNECTED USER IS IN SERVER ADMINISTRATOR ROLE:
#
# === Usage: ===
# dbo.[AUX:IsInServerAdminRole]()
#
==================================================================================================*/

return CONVERT( bit, ISNULL(IS_SRVROLEMEMBER('sysadmin'),0) )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:IsInServerAdminRole]() 'Is in SQL-administrator role'
*/
--:SetVar Function "AUX:ToSingleLine"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToSingleLine' )
   drop function [AUX:ToSingleLine]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:ToSingleLine]( @Text nvarchar(max) )
returns nvarchar(max)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# TEXT TRANSFORMATION (OF STRINGS, CONCATENATED THROUGH CR+LF) TO SINGLE LINE (WITHOUT LINE FEEDS):
#
# === Usage: ===
# dbo.[AUX:ToSingleLine]( <String with CR-n-LFs> )
#
==================================================================================================*/

if @Text is null return null

set @Text = TRIM( @Text )

declare @Result nvarchar(max), @String nvarchar(max), @L int, @P int, @Ch nchar, @CRLF bit, @PreCRLF bit
select @Result = '', @String = '', @L = LEN( @Text ), @P = 1
while @P <= @L
begin
   set @Ch = SUBSTRING( @Text, @P, 1 )
   set @CRLF = case
                  when @Ch in ( char(13),char(10) )
                  then 1 else 0
               end
   if @P = @L or @CRLF = 1
   begin
      if @P = @L or @PreCRLF <> 1
      begin
         if @P = @L and @CRLF = 0
            set @String = @String + @Ch
         set @String = TRIM( @String )
         if @String <> ''
            set @Result = @Result +
               case
                  when @Result<>''
                  then ' ' else ''
               end + @String
      end
      set @String = ''
   end
   else
      set @String = @String + @Ch
   select @PreCRLF = @CRLF, @P = @P + 1
end

return @Result

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:ToSingleLine](
N'  String-1.  '+CHAR(13)+CHAR(10)+
N'String-2.  '+CHAR(13)+
N'  String-3.  '+CHAR(10)
)+'”' 'String without CRLFs'
*/
/*==================================================================================================
#
# 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'
*/
