:SetVar Function "AUX:PadEnd.Ext"
:r $(DropFunctionScript_AUX)
create function [$(Function)]
(
   @String           $(dt_String_AUX),
   @WidthForPadding  int,
   @PadChar          nchar
)
returns $(dt_String_AUX)
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'
*/
