Combining Columns and Tables

How to Merge Two Columns in SQL Server

Learn how to merge two columns in SQL Server with +, CONCAT() and CONCAT_WS(), handle NULLs and spacing, and avoid common type errors in your queries.

On this page
  1. Use + to join two columns
  2. Handle NULL values with CONCAT_WS
  3. Convert numbers and dates before joining
  4. Trim spaces and watch CHAR columns
  5. Store the merged value in a computed column
  6. Use || in SQL Server 2025 and later
  7. Don’t confuse merging columns with the MERGE statement
  8. Quick checklist

Use + to join two columns

To merge two text columns in SQL Server, join them with the + operator in the SELECT list, and put a string literal between them for the separator:

SELECT FirstName + ' ' + LastName AS FullName
FROM dbo.Employees;

Each row returns one value, such as Maria Lopez. The + operator is available in all versions of SQL Server. It only joins strings, so numbers and dates need converting first, as covered below.

Handle NULL values with CONCAT_WS

Since SQL Server 2017, + returns NULL if any part of the expression is NULL, because the CONCAT_NULL_YIELDS_NULL setting is always on. If some employees have no middle name, the whole result is NULL for those rows:

SELECT FirstName + ' ' + MiddleName + ' ' + LastName AS FullName
FROM dbo.Employees;  -- NULL for every row where MiddleName is NULL

CONCAT() treats NULL as an empty string instead. It has been available since SQL Server 2012. The result keeps both spaces around the missing value:

SELECT CONCAT(FirstName, ' ', MiddleName, ' ', LastName) AS FullName
FROM dbo.Employees;  -- two spaces where MiddleName is NULL

CONCAT_WS() goes a step further. It skips NULL values and doesn’t add the separator next to them. It needs SQL Server 2017 or later, and it requires a separator plus at least two values:

SELECT CONCAT_WS(' ', FirstName, MiddleName, LastName) AS FullName
FROM dbo.Employees;

If you want a visible fallback instead of skipping the value, wrap the column in ISNULL(MiddleName, ‘N/A’) or COALESCE(). The general idea is covered in what is coalesce() in SQL. For a numeric column, the fallback is a number, and how to get 0 instead of NULL in SQL covers that case.

Convert numbers and dates before joining

+ works on strings. If one side is a number, SQL Server tries to convert the text to that number. So 'Order ' + OrderId fails with a conversion error when OrderId is an int. Cast the number first:

SELECT 'Order ' + CAST(OrderId AS VARCHAR(20)) AS OrderLabel
FROM dbo.Orders;

CONCAT() converts numbers for you, so CONCAT('Order ', OrderId) works without a cast.

The opposite problem also happens. When both columns are numbers, + adds them. Price + Tax returns a sum, not joined text.

Dates need the same care. Convert them explicitly with CONVERT() and a style number so the format is predictable.

Trim spaces and watch CHAR columns

If a column is defined as CHAR(n), SQL Server pads each value with spaces up to n characters. Those trailing spaces end up in the middle of your merged value. Remove them with RTRIM(), or change the column to VARCHAR or NVARCHAR:

SELECT RTRIM(FirstName) + ' ' + RTRIM(LastName) AS FullName
FROM dbo.Employees;

The other functions for removing spaces are covered in what does trim() do in SQL.

Store the merged value in a computed column

If you read the combined value often, add a computed column. SQL Server calculates it from the source columns, so you don’t have to update it yourself when FirstName or LastName changes:

ALTER TABLE dbo.Employees
    ADD FullName AS (FirstName + ' ' + LastName) PERSISTED;

PERSISTED stores the result on disk instead of recalculating it on each read.

Use || in SQL Server 2025 and later

SQL Server 2025 and Azure SQL support the standard || operator:

SELECT FirstName || ' ' || LastName AS FullName
FROM dbo.Employees;

Like + in SQL Server 2017 and later, || returns NULL when any input is NULL. Earlier versions don’t accept ||, so use + or CONCAT() there. For how || works in other databases, see what is the use of || in SQL.

Don’t confuse merging columns with the MERGE statement

SQL Server also has a MERGE statement. It inserts, updates and deletes rows by matching one table to another. It doesn’t combine the columns of a row, so it won’t help with the job described here. For how it works, see how to use merge command in SQL.

Quick checklist

  • Use + or CONCAT() to join text, and CAST() or CONVERT() for numbers and dates.
  • Use CONCAT_WS() on SQL Server 2017 or later when missing values shouldn’t leave gaps.
  • Use RTRIM() on CHAR columns, or change them to VARCHAR or NVARCHAR.
  • Check the output for NULL before you rely on it.

Keep exploring

Guides from other topics

All topics →