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