Concatenate SQL Columns


If you want to combine or concatenate two table columns into one, you may do it by following ways. Many times you have FirstName and LastName in two different columns in a web or desktop application database. If you want a report you need to combine it as a single unit (Name)

Here is the sql statement

Select Concat (Columns1, Columns2) from Table

You may want to use a custom title, do like this

Select Concat (Columns1, Columns2) as Column3 from Table

You may want to add a space in the middle of two columns, do like this

Select Concat (Columns1, ” “, Columns2) as Column3 from Table

Example

Select Concat (FirstName, ” “, LastName) as Customer Name from Table

The result will be a single column contains First Name and Last Name in between a space.

If the above methoed doesn’t work you may do it like this (SQL server doesn’t support Concat() method)

SELECT (ColumnA + ColumnB) AS ColumnZ
FROM Table;

You may try this

select columnA||columnB from TABLEA; (Concats column A and B)

Another way of Concatenation

SELECT one + ‘ ‘ + two AS onetwo FROM table


About Yasir Imran

Yasir Imran is a Pakistani living in Saudi Arabia. He writes because he want to express his thoughts. It is not necessary you agree what he says, You may express your thoughts in your comments. Once reviewed and approved your comments will appear in the discussion.
This entry was posted in Edu, Web and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s