--: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.)'
*/
