SQL SERVER – MySQL – PostgreSQL – How to Concat Strings?

As a regular reader, you may know that I now a days work with MySQL and SQL Server both at the same time. Working with two different products have changed quite a few things in how I write code. Here is an example of that – I changed myself about how I CONCAT strings. Here is how to concat strings so the same code runs everywhere.

Earlier with SQL Server

Earlier I used to use ‘+’ (Plus) operator when I was concatenating strings. Here is the script for the same:


SELECT 'FirstName' + ' Last Name' AS FullName;

Now with SQL Server


SELECT CONCAT('FirstName',' Last Name') AS FullName;

SQL Server Query Tool window with query for concatenating names.

The reason I use the CONCAT function instead of ‘+’ (Plus) operator is because CONCAT functions work in MySQL as well. Here is the example how the same scripts work in MySQL without changing any code.

Concat full name query.

Additionally, the same code we can use with Postgres as well. Here is the example how the same scripts work in PostgreSQL without changing any code.

SQL Server Fullname Query.

Here is a question to you, does the same code works with Oracle? If you know the answer, I request you to leave a comment here. I am very confident that the same code works with many other databases as well, if you know the name of the same, please leave a note.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

MySQL, PostgreSQL, SQL Function, SQL Scripts, SQL Server
Previous Post
Developer – 10 Phrases Developer Use Too Often
Next Post
SQL SERVER – MySQL – LIMIT and OFFSET – Skip and Return Only Next Few Rows – Paging Solution

Related Posts

3 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.