How to concatenate in SQL Server

13    Asked by juanka_2802 in SQL Server , Asked on May 6, 2025

What are the different ways to concatenate columns or values in a SQL query? Learn how SQL Server handles string concatenation using operators and built-in functions.

Answered by Larry McLeod

In SQL Server, concatenating strings means joining two or more string values into one. It’s commonly used when combining column values in a SELECT query to produce readable output. There are a few simple ways to do this.

 Methods to Concatenate Strings in SQL Server:

Using the + Operator

 This is the most common way to join strings.

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

 If any value is NULL, the result will also be NULL unless handled with ISNULL() or COALESCE().

Using CONCAT() Function

 Introduced in SQL Server 2012, this function automatically handles NULL values by treating them as empty strings.

  SELECT CONCAT(FirstName, ' ', LastName) AS FullName FROM Employees;

Using FORMAT() for formatted output

 If you're building more structured or formatted strings (like addresses or currency), FORMAT() can be helpful:

  SELECT FORMAT(Salary, 'C') AS FormattedSalary FROM Employees;

 Notes:

  • Always handle NULL values to avoid unexpected NULL results.
  • CONCAT() is safer and more readable when dealing with many values or possible NULLs.

Concatenation in SQL Server is straightforward, but using the right method ensures your output is clean and accurate. Do you have a specific use case in mind?



Your Answer

Interviews

Parent Categories