CONCAT() function in SQL Server
Last Updated :
28 Dec, 2020
Improve
CONCAT() :
This function in SQL Server helps to concatenate two or more strings together. CONCAT() function can accept a minimum of 2 parameters and a maximum of 254 parameters.
Syntax :
Example-3 :
Concatenating numerical expression using CONCAT() function, here in place of string we combined numeric values.
CONCAT(string_1, string_2, .......string_n)Parameters :
- string_1, string_2, .......string_n - The given strings which need to be concatenated.
- SQL Server 2017
- SQL Server 2016
- SQL Server 2014
- SQL Server 2012
- Concatenating 3 strings together with space in between -
SELECT CONCAT('PYTHON', ' ', 'is', ' ', 'fun!!!') As Combined;
Output :Combined PYTHON is fun!!! - Concatenating more than 3 strings together -
SELECT CONCAT ('Every', 'next', 'level', 'of', 'your', 'life', 'demands', 'a', 'new', 'you!') As Combined;
Output :Combined Everynextlevelofyourlifedemandsanewyou!
DECLARE @Str1 AS VARCHAR(100)='Think' DECLARE @Str2 AS VARCHAR(100)='-' DECLARE @Str3 AS VARCHAR(100)='green' DECLARE @Str4 AS VARCHAR(100)=' ' DECLARE @Str5 AS VARCHAR(100)='Be' DECLARE @Str6 AS VARCHAR(100)='-' DECLARE @Str7 AS VARCHAR(100)='green' SELECT CONCAT(@Str1, @Str2, @Str3, @str4, @str5, @str6, @str7) AS Combined;Output :
Combined |
---|
Think-green Be-green |
SELECT CONCAT(13, 03, 1999) AS Combined;Output :
Combined |
---|
1331999 |