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