T-SQL Tutorial

Concat TSQL Tutorial


Concat function

The string functionCONCAT has the role of concatenating two or more strings into a single string. The CONCAT function can be used with NULL values, CONCAT function implicitly converts null values to empty strings.


Basic Concat Example

SELECT CONCAT ('Daniel', ' - ','Scott') AS FullName;
Result: Daniel - Scott


Using CONCAT with NULL values

SELECT CONCAT( 'Test', NULL, 'SQL' );
Result: TestSQL


Complex Concat Example

Cities table:

CITY_IDNAMESTATE
1New YorkNew York
2Los AngelesCalifornia
3ChicagoIllinois
4San AntonioTexas
5San DiegoCalifornia

SELECT CONCAT (city_id, ' / ', name, ' / ', state) AS Result
FROM cities WHERE state='California';

Concat Result:

Result
2 / Los Angeles / California
5 / San Diego / California

See also: T-SQL Functions -> Charindex -> Left -> Len -> Lower -> Ltrim