SQL Server > String related

Concatenate more than one columns in SQL Server

How to concatenate more than one columns in SQL Server?


To concatenate more than one columns into a single value, we can user CONCAT function like below. The good thing is that even if columns are of different types, it can be concatenated. Like we can concatenate string with integer, datetime etc.

SELECT CONCAT(
                           FirstName,
                           SPACE(1),
                           LastName,
                           SPACE(1),
                           Age,
                           space(2),
                           Active
                           )
FROm PersonalDetails

Here, we are concatenating FirstName a space separated by LastName one space separated by Age and two space separated by Active field from the PersonalDetails table.

 Views: 9177 | Post Order: 71



Write for us






Hosting Recommendations