In SQL Server and Azure, if you need to concatenate two or more strings, you can use the T-SQL CONCAT()
function. As with any basic concatenation operation, this function joins the strings together, end-to-end.
But what if you need to add a separator between each string?
For example, you might want to make a comma-separated list of strings. In this case, you’d want to insert a comma in between each string. Like this:
Paris, France
Instead of this:
ParisFrance
Fortunately, T-SQL provides the CONCAT_WS()
function that helps you do exactly that. The CONCAT_WS()
function works just like the CONCAT()
function, except that it takes an extra argument – the separator you’d like to use.