Concatenates all strings in @Value
using @Separator
as separator. The strings are concatenated according to @SortOrder
in ascending order.
In SQL Server 2017 and higher you can use the built-in STRING_AGG
function instead.
Gets a string with all user names, ordered by last name.
SELECT
SoftadminUtil.String_Join(X.Username, ', ', X.RowNumber)
FROM
(
SELECT
Username,
ROW_NUMBER() OVER (ORDER BY UsernameLast) AS RowNumber
FROM
SoftadminApi.[User]
) X
The concatenated string or NULL if there are no strings to concatenate (i.e the query returned zero rows).