Concatenating two values in SQL Server 2012

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 947
CONCAT() fucntion is introduced in SQL Server 2012. Before to this version, concatenation of two strings is to be done by using + ( plus) operator.

Syntax:
CONCAT ( string1, string2[, string-n])

Example:
SELECT CONCAT( 'FirstName', ' ', 'LastName' ) FullName


Output
FullName
-------------------

FirstName LastName


There are some differences between Plus operator's concatenation and CONCAT function...

The equivalent SQL for the above SELECT using Plus operator is as follows:
SELECT 'FirstName' + ' ' + 'LastName' as FullName


Usage: Mainly used to generate comma separated values of all or some of the columns in a table

Example,
SELECT Conact(EmpID , ' ,', FirstName, ' , ' , LastName, ' , ', Salary) CSVData
FROM EMPLOYEETable

Comments or Responses

Posted by: Nagamma on: 3/22/2015 Level:Starter | Status: [Member] | Points: 10
in which situation it using bandi.ij

Login to post response