String concatenation technique is used quite frequently when we are dealing with legacy systems. Sometimes, we need to add a specific delimiter after every column / expression while concatenating multiple columns / expressions. Earlier, we used multiple functions to achieve it and I have written a detailed article about it earlier.
In SQL Server 2017, a new function shipped namely CONCAT_WS() and you can easily achieve the above mentioned scenario by using CONCAT_WS() function. The database compatibility level MUST be 140 or higher to use this function.
Let me create a sample to demonstrate the functionality of CONCAT_WS() function.
Sample:
USE TEST_DB GO CREATE TABLE Employees( EmployeeID INT IDENTITY(1,1), EmployeeName VARCHAR(100), PrimaryEmail VARCHAR(100), SecondaryEmail VARCHAR(100), AlternateEmail VARCHAR(100) ); GO INSERT INTO Employees (EmployeeName, PrimaryEmail, SecondaryEmail, AlternateEmail) VALUES ('Davolio Nancy', 'Davolio2@gmail.com', 'Davolio_Nancy@gmail.com', 'Nancy99@hotmail.com') ,('Fuller Andrew', 'Fuller_12@gmail.com', 'Andrew_f99@gmail.com', 'Andrew_f9@hotmail.com') ,('Leverling Janet', 'Leverling_42@gmail.com', 'j.Leverling_2@gmail.com', 'Janet_Leverling@hotmail.com') ,('Peacock Margaret', 'Peacock@gmail.com', 'Peacock_12@gmail.com', 'Margaret_Peacock@hotmail.com') GO SELECT * FROM Employees; GO --OUTPUT

Example 1: Concatenate multiple columns & applied semi-colon (;) as a delimiter in between:
- Old approach using add (+) operator:
In the old approach, when we need to concatenate two or more than two columns using Add (+) operator, we need to manually take care of the concatenation and add delimiter (separator) between columns as shown in the example. This approach was used earlier than SQL Server 2017.
USE TEST_DB GO SELECT [EmployeeName] , ([PrimaryEmail]+';'+[SecondaryEmail]+';'+[AlternateEmail]) AS [AllEmails] FROM [Employees]; GO --OUTPUT

- New approach using CONCAT_WS() function:
In the new approach, we just need to use CONCAT_WS() function and it will take care of everything as shown below. It also reduces the complexity of the query since we need to apply delimiter once and the function repeats it automatically, as shown below.

Example 2: Concatenate multiple columns & applied space as a delimiter in between:
- Old approach using add (+) operator:
In this example, we need to use add (+) operator and apply space as a delimiter multiple times in between the columns as shown below.

- New Approach using CONCAT_WS() funcation :
In this example, we just need to use CONCAT_WS() function with space delimiter at once and it will be applied automatically after each column by the function itself.

I found CONCAT_WS() function very much useful when concatenating multiple columns / expressions with delimiter. Let me know if you use this function and how did you find it.