Open In App

CONCAT() function in SQL Server

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 :



CONCAT(string_1, string_2, .......string_n)

Parameters :

Returns :
The function concatenates all the given string and returns them as one whole string.



Applicable to the following versions :

Example-1 :
The general working of CONCAT() function.

Example-2 :
Using a variable with CONCAT() function, we assign the strings to variables and then concatenate them.

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

Example-3 :
Concatenating numerical expression using CONCAT() function, here in place of string we combined numeric values.

SELECT CONCAT(13, 03, 1999) 
AS Combined;

Output :

Combined
1331999
Article Tags :
SQL