In this article I will explain how to write a query to concatenate two columns of data to single column in datatable using SQL server.
SELECT (CONVERT(varchar(50),Column1)+' '+CONVERT(varchar(50),Column2)) AS ConcatnatedColumn FROM
TableName
|
SELECT UserName,FirstName,LastName,(CONVERT(varchar(50),FirstName)+' '+CONVERT(varchar(50),LastName)) AS ConcatnatedColumn FROM
UserDetails
|
SELECT (CAST(ColumnName1
AS varchar(50))+' '+CAST(ColumnName2
AS varchar(50))) AS ConcatnatedColumn FROM
TABLENAME
|
SELECT UserName,FirstName,LastName,(CAST(FirstName AS varchar(50))+' '+CAST(LastName AS varchar(50))) AS ConcatnatedColumn FROM
UserDetails
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|
|


Subscribe by RSS
Subscribe by Email
2 comments :
Nice Article Sir, Thank You.
Hi Suresh,
here i dont see any difference in both ways, as we know that the things which we can do with CONVERT function which can also be possible CAST function in maximum cases at least