The SQL Server CONCAT_WS()
function concatenates two or more strings into one string with a separator. CONCAT_WS()
means concatenate with separator.
The following shows the syntax of the CONCAT_WS()
function:
CONCAT_WS(separator,input_string1,input_string2,[...input_stringN]);
SELECT first_name, last_name, CONCAT_WS(', ', last_name, first_name) full_name FROM sales.customers ORDER BY first_name, last_name;
The following picture shows the partial output: