Wednesday, February 26, 2014

CONCAT Function in SQL Server 2012


The job of CONCAT is to perform a concatenation operation.

Pass CONCAT a number of string arguments and it will concatenate, or join them together and return an output string. If you have used it in Excel you will easily understand it.


The basic structure is as follows:
CONCAT ( string_value_1, string_value_1 [, string_value_n ] )

So now need to check how it works:

For this create a temporary table and add a couple of records:

CREATE TABLE #Customer
(
FirstName varchar(30) NOT NULL,
MiddleName varchar(30) NULL,
LastName varchar(30) NOT NULL
)

INSERT INTO #Customer
VALUES (‘Randheer’, 'Singh', 'Parmar'), ('Raj', NULL, 'kapur')

We have our customer table, so now let us use the CONCAT function to return the
full name of our customers:

SELECT CONCAT(FirstName + ' ', MiddleName + ' ', LastName) AS
CustomerName
FROM #Customer

Result will be
Randheer Singh Parmar
Raj kapur

No comments:

Post a Comment