SQL Server String Concatenation - Upscale Analytics (2024)

This SQL tutorial focuses on SQL ServerString Concatenation, and provides explanations, examples, and exercises. For this lesson’s exercises, use thislink.

This tutorial is a part of several posts explaining how to write basic queries in SQL Server. To read additional posts regarding this subject, please use the following links:

SQL Server Basic String Concatenation

SQL Server String concatenation allows you to append one string to the end of another string. To display the contents of two columns or more under the name of a single column, you can use the concatenation operator(+).
For example, to display the employee’s first name along with his or her last name, use the following SQL Server statement:

SELECT first_name + last_nameFROM employees

The result :

(No column name)------------------------JohnSmith

SQL Server – Concatenate Two Fields with a Space

While in the previous example, the requested result – merging two values from two different columns – has been achieved, the end result is still quite unreadable, as we have no space seperator between the first name and the last name.Therefore, it is advisable to also concatenate a space (‘ ‘) :

SELECT first_name + ' ' + last_nameFROM employees

The result :

(No column name)-----------------------------John Smith

Using a SQL Server Column Alias

To make the result more readable, use a SQL ServerColumn Alias:

SELECT first_name + ' ' + last_name AS 'FullName'FROM employees

The Result :

FullName--------------John Smith

SQL Server – Retrieving additional columns

In SQL Server, If after or before this concatenation you would like to display an additional separate column, simply use a comma (,):

SELECT city, first_name + ' ' + last_name AS 'FullName', salaryFROM employees

The result:

city FullName salary------ ---------- -------------London John Smith 5800

SQL Server – Concatenate more than two values

In SQL Server it is possible to create more complicated concatenations as required:

SELECT 'Employee Name : ' + first_name + ' - '+ last_name AS 'E_DETAILS',FROM employees

The result :

E_Details-----------------------------Employee Name : John- Smith

UpScale Analytics is one of the largest platforms in the world for learning SQL by doing, consisting over 300 SQL exercises at different levels (including solutions), by topics, across over 100 different datasets. More…

SQL Server String Concatenation - Upscale Analytics (2024)
Top Articles
Latest Posts
Article information

Author: Rev. Porsche Oberbrunner

Last Updated:

Views: 5544

Rating: 4.2 / 5 (73 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Rev. Porsche Oberbrunner

Birthday: 1994-06-25

Address: Suite 153 582 Lubowitz Walks, Port Alfredoborough, IN 72879-2838

Phone: +128413562823324

Job: IT Strategist

Hobby: Video gaming, Basketball, Web surfing, Book restoration, Jogging, Shooting, Fishing

Introduction: My name is Rev. Porsche Oberbrunner, I am a zany, graceful, talented, witty, determined, shiny, enchanting person who loves writing and wants to share my knowledge and understanding with you.