Home > DeveloperSection > Forums > Combining two columns data into one using SQL Server
Tanuj Kumar

Total Post:134

Points:940
Posted on    September-22-2014 2:43 AM

 Database Database 
Ratings:


 1 Reply(s)
 635  View(s)
Rate this:

I have a table:

CREATE TABLE CombineCoulmns(

       columnA varchar(15),

       columnB varchar(15)

)

 

With some records:

columnA              columnB

 

One                       Five                       

Two                       Six

Three                    Seven

Four                       Eight

 

I want to show the record as result as following:

comineColumn

One

Two

Three

Four

Five

Six

Seven

Eight

 

I attempt do this:

select columnA+columnB as combineColumn from CombineCoulmns;

 

but it give different Result:

 

comineColumn

OneFive

TwoSix

ThreeSeven

FourEight

 

Please help me.



Anchal Kesharwani
Anchal Kesharwani

Total Post:10

Points:70
Posted on    September-22-2014 2:54 AM

hi tanuj,

You should try to UNION operation for this task:

select columnA as columnName

from CombineCoulmns

union

select columnB as combineName

from CombineCoulmns

 

 

 Note: UNION will keep only one record in case of duplicate values between columnA and columnB. If you want to see the duplicate values repeated in your result, use the UNION ALL operation instead.


Don't want to miss updates? Please click the below button!

Follow MindStick