/***************************************************************************************************
# DIFFERENT TRANSFORMATIONS:
# --------------------------------------------------------------------------------------------------
# SQLAUX scripting library | Author: Sergei Y.Kitáev
# -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/

/*==================================================================================================
# NUMBER CONVERSION TO STRING (“INT” TYPE):
# === Usage: ===
# dbo.[AUX:ToString.Int]( <Number> )
*/
function [AUX:ToString.Int]( @Number int )
returns $(dt_IntStr_AUX)
/*==================================================================================================
# NUMBER CONVERSION TO STRING (“$(dt_HPDecimal_AUX)” TYPE):
# === Usage: ===
# dbo.[AUX:ToString.DHP]( <Number> )
*/
function [AUX:ToString.DHP]( @Number $(dt_HPDecimal_AUX) )
returns $(dt_DecimalStr_AUX)
/*==================================================================================================
# NUMBER CONVERSION TO STRING (“$(dt_MPDecimal_AUX)” TYPE):
# === Usage: ===
# dbo.[AUX:ToString.DMP]( <Number> )
*/
function [AUX:ToString.DMP]( @Number $(dt_MPDecimal_AUX) )
returns $(dt_MPDecimalStr_AUX)
/*==================================================================================================
# NUMBER CONVERSION TO STRING (“$(dt_DecMoney_AUX)” TYPE):
# === Usage: ===
# dbo.[AUX:ToString.DecMoney]( <Number> )
*/
function [AUX:ToString.DecMoney]( @Number $(dt_DecMoney_AUX) )
returns $(dt_MoneyStr_AUX)
/*==================================================================================================
# MONEY CONVERSION TO STRING (“$(dt_DecMoney_AUX)” TYPE) — WITH TWO-DIGIT DECIMAL FRACTION:
# === Usage: ===
# dbo.[AUX:ToString_2.DecMoney]( <Number> )
*/
function [AUX:ToString_2.DecMoney]( @Number $(dt_DecMoney_AUX) )
returns $(dt_DecMoneyStr_2_AUX)
/*==================================================================================================
# CONVERSION FROM DATE TO STRING:
# - “MM/DD/YYYY” (EN);
# - “DD.MM.YYYY” (RU)
# === Usage: ===
# dbo.[AUX:ToString.Date]( <Date> )
*/
function [AUX:ToString.Date]( @Date datetime2 )
returns $(dt_NormalDateStr_AUX)
/*==================================================================================================
# CONVERSION FROM TIME TO STRING:
# - “HH::MM::SS” (EN)
# - “HH::MM::SS” (RU)
# === Usage: ===
# dbo.[AUX:ToString.Time]( <Date-time> )
*/
function [AUX:ToString.Time]( @Time datetime2 )
returns $(dt_NormalTimeStr_AUX)
/*==================================================================================================
# 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> )
*/
function [AUX:ToString.DateTime]( @DateTime datetime2 )
returns $(dt_WideDateStr_AUX)


/*==================================================================================================
# DATE AS STRING REPRESENTATION:
# - “MM/DD/YYYY”    (EN);
# - “DD.MM.YYYY г.” (RU)
# === Usage: ===
# dbo.[AUX:DateAsString]( <Date> )
*/
function [AUX:DateAsString]( @Date datetime2 )
returns $(dt_WideDateStr_AUX)
/*==================================================================================================
# DATE AS STRING REPRESENTATION:
# - “MM/DD/YYYY”    (EN);
# - “DD.MM.YYYY г.” (RU)
# (EXTENDED VERSION)
# === Usage: ===
# dbo.[AUX:DateAsString.Ext]( <Date>, null, null )
# dbo.[AUX:DateAsString.Ext]( <Date>, 1, null )
# dbo.[AUX:DateAsString.Ext]( <Date>, 1, 0 )
*/
function [AUX:DateAsString.Ext]( @Date datetime2, @PostscriptWithYearSign bit )
returns $(dt_WideDateStr_AUX)
/*==================================================================================================
# 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> )
*/
function [AUX:DateTimeAsString]( @DateTime datetime2 )
returns $(dt_WideDateStr_AUX)
/*==================================================================================================
# DATE-TIME AS STRING REPRESENTATION:
# - “MM/DD/YYYY HH:MM:SS” (EN);
# - “DD.MM.YYYY HH:MM:SS” (RU)
# (EXTENDED VERSION)
# === 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 )
*/
function [AUX:DateTimeAsString.Ext]( @DateTime datetime2, @PostscriptWithYearSign bit )
returns $(dt_WideDateStr_AUX)


/*==================================================================================================
# 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 )
*/
function [AUX:ToStringFS.Int]( @Number int, @AbsValueWidthForZeroPadding int=null )
returns $(dt_AnsiString_AUX)
/*==================================================================================================
# 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 )
*/
function [AUX:ToStringFS.DHP]( @Number $(dt_HPDecimal_AUX),
                               @AbsValueWidthForZeroPadding int = null )
returns $(dt_AnsiString_AUX)
/*==================================================================================================
# 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 )
*/
function [AUX:ToStringFS.DMP]( @Number $(dt_MPDecimal_AUX),
                               @AbsValueWidthForZeroPadding int = null )
returns $(dt_AnsiString_AUX)
/*==================================================================================================
# 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 )
*/
function [AUX:ToStringFS.DecMoney]( @Number $(dt_DecMoney_AUX),
                                    @AbsValueWidthForZeroPadding int = null )
returns $(dt_AnsiString_AUX)
/*==================================================================================================
# 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 )
*/
function [AUX:ToStringFS_2.DecMoney]( @Number $(dt_DecMoney_AUX),
                                      @AbsValueWidthForZeroPadding int = null )
returns $(dt_AnsiString_AUX)


/*==================================================================================================
# NUMBER CONVERSION TO STRING, WITH VARIABLE PRECISION (“$(dt_HPDecimal_AUX)” TYPE):
# === Usage: ===
# dbo.[AUX:ToStringVS.DHP]( <Number> )
*/
function [AUX:ToStringVS.DHP]( @Number $(dt_HPDecimal_AUX) )
returns $(dt_AnsiString_AUX)
/*==================================================================================================
# NUMBER CONVERSION TO STRING, WITH VARIABLE PRECISION (“$(dt_MPDecimal_AUX)” TYPE):
# === Usage: ===
# dbo.[AUX:ToStringVS.DMP]( <Number> )
*/
function [AUX:ToStringVS.DMP]( @Number $(dt_MPDecimal_AUX) )
returns $(dt_AnsiString_AUX)


/*==================================================================================================
# LOGICAL FLAG (1/0) OF “BIT” TYPE — FOR INTEGER NUMBER (ONE FOR SIGNIFICANT NOT NULL):
# === Usage: ===
# dbo.[AUX:LogicalSign.Int]( <Number> )
*/
function [AUX:LogicalSign.Int]( @Number int )
returns bit
/*==================================================================================================
# LOGICAL FLAG (1/0) OF “BIT” TYPE — FOR BIG INTEGER (ONE FOR SIGNIFICANT NOT NULL):
# === Usage: ===
# dbo.[AUX:LogicalSign.BigInt]( <Number> )
*/
function [AUX:LogicalSign.BigInt]( @Number bigint )
returns bit
/*==================================================================================================
# LOGICAL FLAG (1/0) OF “BIT” TYPE — ONE FOR SIGNIFICANT NOT NULL (TYPE “FLOAT”):
# === Usage: ===
# dbo.[AUX:LogicalSign.Float]( <Number> )
*/
function [AUX:LogicalSign.Float]( @Number float )
returns bit
/*==================================================================================================
# LOGICAL FLAG (1/0) OF “BIT” TYPE — ONE FOR SIGNIFICANT NOT NULL (“$(dt_HPDecimal_AUX)”):
# === Usage: ===
# dbo.[AUX:LogicalSign.DHP]( <Number> )
*/
function [AUX:LogicalSign.DHP]( @Number $(dt_HPDecimal_AUX) )
returns bit
/*==================================================================================================
# LOGICAL FLAG (1/0) OF “BIT” TYPE — ONE FOR SIGNIFICANT NOT NULL (“$(dt_MPDecimal_AUX)”):
# === Usage: ===
# dbo.[AUX:LogicalSign.DMP]( <Number> )
*/
function [AUX:LogicalSign.DMP]( @Number $(dt_MPDecimal_AUX) )
returns bit
/*==================================================================================================
# LOGICAL FLAG (1/0) OF “BIT” TYPE — ONE FOR SIGNIFICANT NOT NULL (“$(dt_DecMoney_AUX)”):
# === Usage: ===
# dbo.[AUX:LogicalSign.DecMoney]( <Number> )
*/
function [AUX:LogicalSign.DecMoney]( @Number $(dt_DecMoney_AUX) )
returns bit
/*==================================================================================================
# LOGICAL FLAG (1/0) OF “BIT” TYPE — FOR STRING VALUE (ONE FOR NON-EMPTY STRING):
# === Usage: ===
# dbo.[AUX:LogicalSign.Str]( <String> )
*/
function [AUX:LogicalSign.Str]( @String $(dt_String_AUX) )
returns bit
/*==================================================================================================
# LOGICAL FLAG (1/0) OF “DATETIME” TYPE (ONE FOR NOT NULL DATE-TIME VALUE):
# === Usage: ===
# dbo.[AUX:LogicalSign.DateTime]( <Number> )
*/
function [AUX:LogicalSign.DateTime]( @DateTime datetime2 )
returns bit


/*==================================================================================================
# CONVERSION TO ROMAN NUMBER INSCRIPTION (WORKING VALUES: 1..100):
# === Usage: ===
# dbo.[AUX:ToRomanNumber]( <Number> )
*/
function [AUX:ToRomanNumber]( @Number int )
returns $(dt_RomanNumber_AUX)
/*==================================================================================================
# CONVERSION TO ROMAN NUMBER INSCRIPTION (WORKING VALUES: 1..100):
# (EXTENDED VERSION)
# === Usage: ===
# dbo.[AUX:ToRomanNumber.Ext]( <Number>, 0 )
# dbo.[AUX:ToRomanNumber.Ext]( <Number>, 1 )
*/
function [AUX:ToRomanNumber.Ext]( @Number int,
                                  @FormatUnsupportedValue bit = 1 )
returns $(dt_RomanNumber_AUX)


/*==================================================================================================
# 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 )
*/
function [AUX:FormatNumByWidth]( @NumberAsString $(dt_String_AUX),
                                 @WidthForPadding int,
                                 @ExpressiveDisplayNull bit = 0 )
returns $(dt_AnsiString_AUX)


/*==================================================================================================
# 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 )
*/
function [AUX:FormatByWidth.Int]( @Number int,
                                  @WidthForPadding int = null,
                                  @ExpressiveDisplayNull bit = 0 )
returns $(dt_AnsiString_AUX)
/*==================================================================================================
# 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 )
*/
function [AUX:FormatByWidth.DHP]( @Number $(dt_HPDecimal_AUX),
                                  @WidthForPadding int = null,
                                  @ExpressiveDisplayNull bit = 0 )
returns $(dt_AnsiString_AUX)
/*==================================================================================================
# 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 )
*/
function [AUX:FormatByWidth.DMP]( @Number $(dt_MPDecimal_AUX),
                                  @WidthForPadding int = null,
                                  @ExpressiveDisplayNull bit = 0 )
returns $(dt_AnsiString_AUX)
/*==================================================================================================
# 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 )
*/
function [AUX:FormatByWidth.DecMoney]( @Number $(dt_DecMoney_AUX),
                                       @WidthForPadding int = null,
                                       @ExpressiveDisplayNull bit = 0 )
returns $(dt_AnsiString_AUX)
/*==================================================================================================
# 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 )
*/
function [AUX:FormatByWidth_2.DecMoney]( @Number $(dt_DecMoney_AUX),
                                         @WidthForPadding int = null,
                                         @ExpressiveDisplayNull bit = 0 )
returns $(dt_AnsiString_AUX)


/*==================================================================================================
# GUID FORMATTING (CONVERSION TO STRING WITH BOUNDING CURLY BRACKETS):
# === Usage: ===
# dbo.[AUX:FormatGUID]( <Itendifier> )
*/
function [AUX:FormatGUID]( @Identifier uniqueidentifier )
returns $(dt_GuidWithBracketsStr_AUX)


/*==================================================================================================
# 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
*/
procedure [AUX:TryMakeDateFromStr] @DateString              $(dt_String_AUX),
                                   @ResultDate              datetime2 out,
                                   @SignificantLengthStrict bit = 0
