SQL Query

SQL Server: How to Concatenate Strings in SQL

SQL Server guide: Combine multiple strings or columns into one using CONCAT or || operator.

This guide is specifically for SQL Server syntax.

How to Concatenate Strings in SQL

Combine multiple strings or columns into one using CONCAT or || operator.

Quick Answer

SELECT CONCAT(first_name, ' ', last_name) as full_name FROM users;

Explanation

CONCAT joins strings together. || operator works in PostgreSQL/Oracle. CONCAT_WS adds a separator between values. Use COALESCE to handle NULLs.

Query Variants

Concat

SELECT CONCAT(first_name, ' ', last_name) as full_name FROM users;

Pipe

SELECT first_name || ' ' || last_name as full_name FROM users;

Concat Ws

SELECT CONCAT_WS(', ', city, state, country) as location FROM addresses;

With Null

SELECT CONCAT(COALESCE(prefix, ''), name) as full_name FROM users;

Pro Tips

  • CONCAT_WS handles separators automatically
  • NULL in CONCAT may return NULL (database-dependent)
  • Use COALESCE for NULL-safe concatenation

Related SQL Queries

Continue learning with more SQL query examples:


SQL Server-Specific Notes

This page covers SQL Server syntax. Other databases may have different syntax for similar operations.

Related Content

Try it yourself

Practice this query in our interactive SQL sandbox.