

This is one of the differences between T-SQL and MySQL (MySQL also has a CONCAT_WS() function). If the separator itself is a NULL value, the concatenation operation will still be performed, but without a separator.Įxample: SELECT CONCAT_WS(NULL,'Paris', NULL, 'France') AS Location If any of the arguments is a NULL value, SQL Server will skip that value and its separator, but it will still process the others.Įxample: SELECT CONCAT_WS(', ','Paris', NULL, 'France') AS Location Here’s an example of retrieving data from a database, and combining two columns into one, separated by a comma: SELECT CONCAT_WS(', ', city.Name, country.Name ) AS Location SELECT CONCAT_WS(' - ','Paris', 'France') AS Location Here’s the same example as the previous one, except this one uses a different separator. If the character set and collation are not. Procedure parameters can be declared with any character set/collation. The separator can be an expression of any character type ( char, nchar, nvarchar, or varchar). MariaDB stores the sqlmode system variable setting that is in effect at the time a routine is created, and always executes the routine with this setting in force, regardless of the server SQL mode in effect when the routine is invoked. There’s nothing to say that the separator must be a comma. Here’s an example: SELECT CONCAT_WS(',','Paris', 'France') AS Location Īnd you can add a space in there if you want: SELECT CONCAT_WS(', ','Paris', 'France') AS Location The CONCAT_WS() function works just like the CONCAT() function, except that it takes an extra argument – the separator you’d like to use. Like this: Paris, Franceįortunately, T-SQL provides the CONCAT_WS() function that helps you do exactly that. In this case, you’d want to insert a comma in between each string. SQL Server 2016 introduced a new built-in table-valued function, STRINGSPLIT that splits the provided input string by a specified separation character and returns the output separated values in the form of table, with a row for each delimited value between each separator character. As with any basic concatenation operation, this function joins the strings together, end-to-end.īut what if you need to add a separator between each string?įor example, you might want to make a comma-separated list of strings. In SQL Server and Azure, if you need to concatenate two or more strings, you can use the T-SQL CONCAT() function.
