How do I concatenate strings with SQL?

 

Much unlike their string-to-date conversion differences, SQL Server and MySQL use a function for concatenating strings – concat() – which is identical in syntax and performance on both platforms.

 

/*--------------------MySQL--------------------------------------*/
select
Concat('2017','-Feb') as TwoStrings,
Concat('2017','-','Feb') as MultipleStrings
----------------------SQL Server-----------------------------------
select
Concat('2017','-Feb') as TwoStrings,
Concat('2017','-','Feb') as MultipleStrings
----------------------PostgreSQL-----------------------------------
select
'2017' || '-Feb' as TwoStrings,
'2017' || '-' || 'Feb' as MultipleStrings
---------------------Vertica---------------------------------------
select
--concat in vertica is only applicable to two strings
Concat('2017','-Feb') as TwoStrings
Concat('2017',Concat('-', 'Feb')) as MultipleStrings
'2017' || '-' || 'Feb' as MultipleStrings

As you’ll see above, the odd ones out this time round are PostgreSQL and Vertica.

Although concat() is also available in Vertica, it can only join two strings together on this platform

To join multiple strings in Vertica, you’ll either need to use it multiple times or employ the  ‘||’ operator

Happy SQL-ing!