COMBINING TWO COLUMNS DATA INTO ONE USING SQL SERVER

Tanuj Kumar

Total Post:134

Points:940
Posted by  Tanuj Kumar
 929  View(s)
Ratings:
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.

  1. Anchal Kesharwani

    Post:10

    Points:70
    Re: Combining two columns data into one using SQL Server

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!