Show row data into columns

Hi guys
i have data coming in multiple rows and want to show same data in columns like multiple colours per product. colour are fixed in numbers i.e only three colours are there per product not more than that..
sample data is like this
id product_name colour
101 A red
101 A black
101 A Green
result required:-
id product_name colour1 colour2 colour3
101 A red black green
thanks & Regards

Hi,
That's called a Pivot.  In Oracle 8.1 and higher, you can use ROW_NUMBER, CASE, and an aggregate function, such as MIN for pivoting. (Starting in Oracle 11, there's SELECT ... PIVOT.)
You didn't post CREATE TABLE and INSERT statements for your table, so I'll use scott.emp to illustrate:
WITH   got_r_num   AS
    SELECT  deptno
    ,       job
    ,       ename
    ,       ROW_NUMBER () OVER ( PARTITION BY  deptno
                                 ,             job
                                 ORDER BY      ename
                                )  AS r_num
    FROM    scott.emp
SELECT    deptno
,         job
,         MIN (CASE WHEN r_num = 1 THEN ename END)   AS ename_1
,         MIN (CASE WHEN r_num = 2 THEN ename END)   AS ename_2
,         MIN (CASE WHEN r_num = 3 THEN ename END)   AS ename_3
FROM      got_r_num
GROUP BY  deptno
,         job
ORDER BY  deptno
,         job
Output:
    DEPTNO JOB       ENAME_1    ENAME_2    ENAME_3
        10 CLERK     MILLER
        10 MANAGER   CLARK
        10 PRESIDENT KING
        20 ANALYST   FORD       SCOTT
        20 CLERK     ADAMS      SMITH
        20 MANAGER   JONES
        30 CLERK     JAMES
        30 MANAGER   BLAKE
        30 SALESMAN  ALLEN      MARTIN     TURNER
If you do happen to have more than 3 items, the query still works, but only the first 3 are shown.  (In deptno=10, there is a 4th SALESMAN named WARD.)

Similar Messages

  • How to convert row data into columns without using pivot table?

    Hello guys
    I have a report that has several columns about sales call type and call counts
    It looks like this:
    Calls Type Call Counts
    Missed 200
    Handled 3000000
    Rejected 40000
    Dropped 50000
    Now I wanna create a report that look like this:
    Missed call counts Handled Call counts Rejected Counts Drop counts Other Columns
    200 300000000 40000 50000 Data
    So that I can perform other calculations on the difference and comparison of handled calls counts vs other call counts..
    I know pivot table view can make the report look like in such way, but they cant do further calculations on that..
    So I need to create new solid columns that capture call counts based on call types..
    How would I be able to do that on Answers? I don't have access to the RPD, so is it possible to do it sololy on answers? Or should I just ask ETL support on this?
    Any pointers will be deeply appreciated!
    Thank you

    Thanks MMA
    I followed your guidance and I was able to create a few new columns of call missed count, call handled counts and call abandoned counts.. Then I create new columns of ave missed counts, ave handled counts and so forth..
    Then I went to the pivot view, I realized there is a small problem.. Basically the report still includes the column "call types" which has 3 different types of call "miss, abandon and handled". When I exclude this column in my report, the rest of the measures will return wrong values. When I include this column in the report, it shows duplicate values by 3 rows. It looks like this:
    Queue name Call types Call handled Call missed Call abondoned
    A Miss 8 10 15
    A Handled 8 10 15
    A Abandoned 8 10 15
    in pivot table view, if I move call type to column area, the resulted measures will become 8X3, 10X3 and 15X3
    So is there a way to eliminate duplicate rows or let the system know not to mulitply by 3?
    Or is this as far as presentation service can go in terms of this? Or should I advice to provide better data from the back end?
    Please let me know, thanks

  • Convert table row data into column - 8i

    hello all,
    i have a table with the following data
    Machine Time
    MAC1 - 1
    MAC2 - 2
    MAC3 - 3
    MAC4 - 4
    MAC5 - 5
    and want to have a query as only for the mac1, mac2 and mac3
    MAC1 MAC2 MAC3
    1 2 3
    how to acheived this...i am on 8i thanks in adv.
    KK

    SELECT SUM(DECODE(MACHINE,'MAC1',TIME)) "MAC1",
    SUM(DECODE(MACHINE,'MAC2',TIME)) "MAC2" ,
    SUM(DECODE(MACHINE,'MAC3',TIME)) "MAC3" FROM TABLENAME

  • How to send multiple row data into an internal table??

    I have a view with table control.i want to select multiple row and send all the row data into an internal table.i am able to select multiple row but all the selected row data is not going to the internal table.....only a particular row data which is lead selected is going.
    Do anyone can help me regarding this issue?
    Thanks in advance,
    Subhasis.

    Hey,
    Some code example:
    declaring an internal table and work area to get all the elements from the node.
    data : lt_Elements type  WDR_CONTEXT_ELEMENT_SET,
             ls_Element type  WDR_CONTEXT_ELEMENT_SET,
    considering flights is my node.
             lt_data type sflight.
    Node_Flights is the ref of the node to which ur table is binded.
    Use Code Inspector to read the node.
    lt_Element = Node_Flights->GET_ELEMENTS
    loop at lt_elements into ls_Element.
    l_bollean =   ls_elements->is_selected ( returns abap true/false ).
        if l_bollean IS INITIAL.
           append ls_Element to lt_data.
       endif.
    Hope this would help.
    Cheers,
    Ashish

  • How to fetch single row data into multiple columns

    Hi Have a cursor
    which will have SELECT Sun_hrs,Mon_hrs,Tue_hrs,Wed_hrs,Thu_hrs,Fri_hrs,Sat_hrs from OTMaster;
    now my cursor has one row of the above columns with this row data I want to insert into other tale as column wise
    ex:
    my row is like this: Sun_hrs,Mon_hrs,Tue_hrs,Wed_hrs,Thu_hrs,Fri_hrs,Sat_hrs
    01:00 01:00 01:00 01:00 01:00 01:00 01:00
    now I want to insert the above data into table with loop along with weekday
    weekday, OTHrs
    1 01:00
    2 01:00
    3 01:00
    4 01:00
    5 01:00
    6 01:00
    7 01:00
    which type of variable I need to fetch the records, rowtype or tabletype,
    plz help me

    thank you for information, and now I am using UNPIVOT below is my query
    SELECT * FROM OTCEILINGMASTER
    UNPIVOT(OTHOURS FOR WEEK_DAY IN (SUN_CEILING_HRS AS '1',MON_CEILING_HRS AS '2',TUE_CEILING_HRS AS '3',
    WED_CEILING_HRS AS '4',THU_CEILING_HRS AS '5',FRI_CEILING_HRS AS '6',SAT_CEILING_HRS AS '7'));
    when I am selecting all the columns (select * from OTCEILINGMASTER) then only the above query is executing I want only two columns from the table however my table has 10 columns.
    please looking into this

  • Show Rows Where Two Columns have Same Data

    Hello,
    I have a spreadsheet that I need to sort by showing me all the rows where the data is equal between two columns.
    I.E. I have a column called Last Name and I have another column, U, with some of those Last Names, I want to sort the spreadsheet to show me only the rows that match up with the same Last Name in coumn a and U.
    Thanks for any help.
    L

    To sort the table:
    Add two columns to the table. For this discussion, I'll refer to them as columns AA and AB.
    In AA2, enter: =ROW()
    Fill to the bottom of the table. With all f these cells selected, Copy, then Edit > Paste Values.
    This gives you a column you can sort by to restore the original order of the table.
    In AB2, enter: =IF(A=U,U," ") using option-space between the double quotes.
    Visually, this will repeat the duplicated names once more in column AB.
    An ascending sort on column AB will bring all rows with duplicate data in columns A and U to the top of the table.
    For greater visibility You might also add a conditional format rule to all of column AB, as I've done here for column D:
    The box to the right of "Text doesn't contain" contains a single 'option-space' character. The ascending sort (on column D) has not yet been done.
    Regards,
    Barry

  • 3 rows data into one column

    Hi,
    Im working with asp application having controls (1 dropdownlist(options--Schedlue,InProcess,On HOld),two textboxes(SSStatusComments,SSGeneralComments))  I want to show output something  like below
    CREATE TABLE [dbo].[EFIWorkStatus1](
    [WID] [int] IDENTITY(1,1) NOT NULL,
    [ST_ID] [int] NULL,
    [SSStatus] [nchar](10) NULL,
    [SSStatusComments] [nvarchar](max) NULL,
    [SSGeneralComments] [text] NULL) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    private void SiteSurveystatusload()
    using (SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ArgentDB"].ConnectionString))
    cn.Open();
    string sql = "Select SSStatus,SSStatusComments from EFIWorkStatus1 where ST_ID=@ST_ID";
    SqlCommand cmd = new SqlCommand(sql, cn);
    cmd.Parameters.AddWithValue("@ST_ID", Request.QueryString["ID1"]);
    using (SqlDataReader reader = cmd.ExecuteReader())
    if (reader.HasRows)
    while (reader.Read())
    txt_SiteSurveyGeneralComments.Text = reader["SSStatus"].ToString() + " " + reader["SSStatusComments"].ToString();
    else
    txt_SiteSurveyGeneralComments.Text = "";
    output in database for above code
    WID ST_ID SSStatus SSStatusComments SSGeneralComments
    1 4 Schedule test in schedule Select
    2 4 In Process test in process Select //expected output Schedule test in schedule in SSGEneralComments
    3 4 On Hold ite on hold On Hold ite on hold //expected output Schedule test in schedule In Process test in process in GeneralComments

    I want to display  the contents in textbox(SSGeneralComments)  .Please check below example.
    Initally user selects dropdown option "Schedule" enter  comments in "SSSTatusComments" click savebtn .It stores in DB,Nexttime user wants to change dropdownlist option "IN Process" and enters comments  in "SSStatusCommentstextbox"    at
    that time previous data(Schedule,comments)  I want to display in       SSGeneralCommentstextbox   click on savebtn it saves in database.nexttime user wants   update option to  Complete and enter comments
    in SSStatusCommentstextbox   I want to display previous  data into   SSGeneralCommentstextbox .       
    dropdownlist1   SSStatusCommentstextbox    SSGeneralCommentstextbox 
    Schedule            test in Schedule   
    IN Process          test in Process               Schedule  test in schedule     //want to display content  in
    this  textbox
    Complete           test in complete            Schedule  test in schedule    //want to display content  in this  textbox
       IN Process test in Process  

  • Transform data into columns

    hello
    i would like to transform rows into columns and need your help
    i have
    table orders
    where we have two columns
    orderid,orderdate
    orderid     order_date
    1234     9/10/2009
    4555     10/1/2009i have order_codes
    have 3 columns
    orderid
    desc
    value
    data for order _codes
    orderid     desc     value
    1234     ch_code1     5789
    1234     ch_date     10/20/2009
    1234     ch_miscval     678.9
    1234     ch_charge     765
    4555     ch_code1     9999
    4555     ch_date     10/0/2009
    4555     ch_miscval     78.9now
    i need to transform data like this
    orderid ==     ch_code1      ==ch_date ==     ch_miscval ==     ch_charge ==     order_date
    1234 ==     5789 ==     10/20/200  ==    678.9 ==     765      == 9/10/2009
    4555 ==     9999 ==     10/1/2009      == 78.9 ==     ---      == 10/1/2009any help is appreciated
    thank you
    Edited by: vg on Nov 2, 2010 9:47 AM

    try this. Hope this helps
    /* Formatted on 2010/11/02 13:29 (Formatter Plus v4.8.8) */
    WITH order_desc AS
         (SELECT 1234 orderid, 'ch_code1' descp, '5789' VALUE
            FROM DUAL
          UNION ALL
          SELECT 1234, 'ch_date', '10/20/2009'
            FROM DUAL
          UNION ALL
          SELECT 1234, 'ch_miscval', '678.9'
            FROM DUAL
          UNION ALL
          SELECT 1234, 'ch_charge', '765'
            FROM DUAL
          UNION ALL
          SELECT 4555, 'ch_code1', '9999'
            FROM DUAL
          UNION ALL
          SELECT 4555, 'ch_date', '10/0/2009'
            FROM DUAL
          UNION ALL
          SELECT 4555, 'ch_miscval', '78.9'
            FROM DUAL),
         order_t AS
         (SELECT 1234 orderid, SYSDATE order_date
            FROM DUAL
          UNION ALL
          SELECT 4555, SYSDATE
            FROM DUAL)
    SELECT   a.orderid, MAX (DECODE (descp, 'ch_code1', VALUE, NULL)) ch_code1,
             MAX (DECODE (descp, 'ch_date', VALUE, NULL)) ch_date,
             MAX (DECODE (descp, 'ch_miscval', VALUE, NULL)) ch_miscval,
             MAX (DECODE (descp, 'ch_charge', VALUE, NULL)) ch_charge,
             MAX (DECODE (descp, 'order_date', VALUE, NULL)) order_date
        FROM order_desc a, order_t b
       WHERE a.orderid = b.orderid
    GROUP BY a.orderid
    Output
       ORDERID CH_CODE1   CH_DATE    CH_MISCVAL CH_CHARGE  ORDER_DATE
          1234 5789       10/20/2009 678.9      765                 
          4555 9999       10/0/2009  78.9                            Edited by: new learner on Nov 2, 2010 10:30 AM

  • TO Display the row data as column in ALV

    Hi experts ,
    Need to display the row data in ALV as column.
    The column of an ALV has the fieldnames of a table , this needs to be displayed as row data , that is as single row.
    How can this can be achieved?

    Hi,
    Actually it is not possible to disaply in multiple lines.
    https://www.sdn.sap.com/sdn/collaboration.sdn?contenttype=url&content=https%3A//forums.sdn.sap.com/thread.jspa%3FforumID%3D50%26threadID%3D49517%26messageID%3D506378%23506378
    https://www.sdn.sap.com/sdn/collaboration.sdn?contenttype=url&content=https%3A//forums.sdn.sap.com/thread.jspa%3FforumID%3D50%26threadID%3D41133%26messageID%3D403371%23403371
    This problem was discussed many times in this forum, u can search for more results.

  • Help cant show link data into a table

    can someone help me how to show the link data into a table?
    i have a data in query it is a link and now i loop the query and show in a table which result all other text, date show but the link show nothing, or 'empty string' while i dump the variable.
    thanks

    nevermind i didt change other part , got it fix
    thanks

  • How to show row data to vertical data(columns) please

    Good Morning,
    Could you please help with this
    I have a table with following two columns
    TechName  Version
    SQLServer 2000
    SQLServer 2003
    SQLServer 2005
    SQLServer 2008
    SQLServer 2008R2
    Oracle    11G
    MSOffice 2000
    MSOffice 2003
    MSOffice 2007
    MSOffice 2010
    How can i show version column this data as vertical component 1 to 5
    TechName Component1 Component2 Component3 Component4   Component5
    SqlServer     2000             2003               2005            
    2008                2008R2
    Oralce          11G              NULL               NULL             
    NULL               NULL
    MSOffice       2000            2003               2007             
    2010                NULL
    Please Help me  with this
    Thank you in Advance
    Asita

    This operation is known as pivoting. The common way to pivot data (transpose rows to columns) in T-SQL is:
    - Grouping (GROUP BY)
    - Spreading values (CASE expression)
    - Aggregating (MIN / MAX / COUNT / etc.)
    Since you have different versions, depending on the value of TechName, then it will be easier if we enumerate each version per value of TechName (row_number in this case).
    with C as (
    select *, row_number() over(partition by TechName order by version) as rn
    from T
    select
        TechName,
        max(case when rn = 1 then Version end) as Component1,
        max(case when rn = 5 then Version end) as Component5
    from
        C
    group by
        TechName;
    If you are going to have more than 5 versions for specific TechName and you do not want to put a quota, then you will have to reach to dynamic sql. Search in this forum by "dynamic pivot" and you will find plenty of examples.
    AMB
    Some guidelines for posting questions...
    AYÚDANOS A AYUDARTE, guía básica de consejos para formular preguntas

  • Merging 2 rows data into a single column in OBIEE

    Hi All,
    Requirement is "Merging 2 rows into a single column"
    Scenario: data from table called "transactions_table"
    Id
    transaction no
    transaction name -------------------------------quantity
    100
    1
    abc
    1000
    100
    2
    def
    2000
    Required out put:
    Id
    Transactions & Quantity
    100
    abc(1000),def(2000)
    Please provide me solution, and let me know if any additional information is required.
    Thanks in advance to all of you.

    can you please share your data like below
    column1, column2 .....
    and where are you trying to do this? at answer or bi admin tool?
    there are a few ways to do this.

  • Merging 2 rows data into a single column in OBIEE 11g

    Hi All,
    Requirement is "Merging 2 rows into a single column"
    Scenario: data from table called *"transactions_table"*
    Id  ------------- transaction no -----------------------  transaction name -------------------------------quantity
    100 ----------- 1 ----------------------- abc ------------------------------ 1000
    100 ----------- 2 ------------------------ def ------------------------------ 2000
    Required out put:
    Id ----------------- Transactions & Quantity
    100 -------------- abc(1000),def(2000)
    Please provide me solution, and let me know if any additional information is required.
    Thanks in advance to all of you.
    Regards,
    chrs

    check the below link, that may help you.
    Re: Horizontal value display
    If it is helpful, please mark as correct or helpful

  • Sort similar data into columns

    I have a data set something liek this:
    1 2 3 4 5
    3 4 5
    2 3 4 5
    2 5
    What I would like to be able to do is find a simple way of putting all the similar values into 1 column, like the following:
    1 2 3 4 5
    0 0 3 4 5
    0 2 3 4 5
    0 2 0 0 5
    In my code I am not actually trying to match exact numbers, I am trying to put in columns numbers that are a few decimal places apart, so numbers like 5.1, 5.2 and 5.3 would be in a single column. Anyone know an easy way to do this?

    LVStudent wrote:
    If I have a 2d array where each row contains the values of peaks positions for a particular graph, then the max width of the array is the length of the array which contains the most peaks. As for the height, I have 360 graphs, so their are 360 rows. Basically I have 360 graphs, where each graph represents the acoustic reflection of an object at 1 degree increments. What I am trying to do is track the changes of specific peaks, however their position moves around a bit so I need a way of lining these peaks up again so I can do a useful analysis. So basically what I do is use the labview peak extractor on each signal, and store the peak positions for each angle in a 2d array. Now I just want to line the data up. For example peak 1 might start at bin 5, then in the next graph jump to bin 5.1 and so on. Peak 2 might start at bin 12 then might jump to bin 12.1, then 12.2. So then I should have something like follows.
    5.1  12
    5.2  12.1
    5.3  12.2
    However when I have data like this:
    1 2 5.1 7     12
    0 0 5.2 12.1
    0 0 5.3 8     12.2
    I am finding it diffult to work out a way to do this.I havent really got any code written for this either that you might be able to lookover, because I dontreally know where to start.
    The bit highlighted in red is the assumption you have made that is wrong. If the peaks are at different points you have a problem...
    What you need to do is create a mega array of all the data points and find out how wide that would be:
    e.g
    1,2,4
    1,2,4.5
    these would still combine to make an array of 3 columns as all of the columns have the same data values.
    1,2,3
    1,2,4
    these would combine to make an array of 4 columns (3 in IT speak and if indexing). The columns would be 1,2,3,4
    If you have too much data to add together into 1 mega array and get the overall width first, the ther are other ways of doing it, I'm just pointing you at the simplest to implement. The other ways require more thought and debugging. (Think outside the box once you can see the problem).
    James

  • Please help - Joining three tables and get row values into Column. Please help!

    Hi,
    There is a SourceTable1 (Employee) with Columns like EmployeeID,Name,DOB.
    There is a sourcetable2 (EmployeeCode) with columns like EmployeeID,Code,Order.
    There is a source table 3  #EmployeeRegioncode  and its columns are (EmployeeID , RegionCode , [Order] 
    The target table 'EmployeeDetails' has the following details. EmployeeID,Name,DOB,Code1,Code2,Code3,Code4,regioncode1
    regioncode2 ,regioncode3 ,regioncode4 
    The requirement is , the value of the target table columns the Code1,code2,code3 ,code4,code5 values should
    be column 'Code' from Sourcetable2 where its 'Order' column is accordingly. ie) Code1 value should be the 'Code' value where [Order] column =1, and Code2 value should be the 'Code' value where [Order] =2, and so on.
    Same is the case for Source table 3- 'Region code' column also for the columns  regioncode1
    regioncode2 ,regioncode3 ,regioncode4 
    Here is the DDL and Sample date for your ref.
    IF OBJECT_ID('TEMPDB..#Employee') IS NOT NULL DROP TABLE #Employee;
    IF OBJECT_ID('TEMPDB..#EmployeeCode') IS NOT NULL DROP TABLE #EmployeeCode;
    IF OBJECT_ID('TEMPDB..#EmployeeDetails') IS NOT NULL DROP TABLE #EmployeeDetails;
    ---Source1
    CREATE table #Employee 
    (EmployeeID int, Empname varchar(20), DOB date )
    insert into #Employee VALUES (1000,'Sachin','1975-12-12') 
    insert into #Employee VALUES (1001,'Sara','1996-12-10') 
    insert into #Employee  VALUES (1002,'Arjun','2000-12-12')
    ---Source2
    CREATE table #EmployeeCode 
    (EmployeeID int, Code varchar(10), [Order] int)
    insert into #EmployeeCode VALUES (1000,'AA',1) 
    insert into #EmployeeCode VALUES (1000,'BB',2)   
    insert into #EmployeeCode  VALUES (1000,'CC',3)  
    insert into #EmployeeCode VALUES  (1001,'AAA',1)  
    insert into #EmployeeCode  VALUES  (1001,'BBB',2)  
    insert into #EmployeeCode  VALUES  (1001,'CCC',3)  
    insert into #EmployeeCode  VALUES  (1001,'DDD',4)  
    insert into #EmployeeCode  VALUES  (1002,'AAAA',1)  
    insert into #EmployeeCode  VALUES  (1002,'BBBB',2)  
    insert into #EmployeeCode  VALUES  (1002,'CCCC',3)  
    insert into #EmployeeCode  VALUES  (1002,'DDDD',4)  
    insert into #EmployeeCode  VALUES  (1002,'EEEE',5)  
    ---Source tbl 3
    CREATE table #EmployeeRegioncode 
    (EmployeeID int, RegionCode varchar(10), [Order] int)
    insert into #EmployeeRegioncode VALUES (1000,'xx',1) 
    insert into #EmployeeRegioncode VALUES (1000,'yy',2)   
    insert into #EmployeeRegioncode  VALUES (1000,'zz',3)  
    insert into #EmployeeRegioncode VALUES  (1001,'xx',1)  
    insert into #EmployeeRegioncode  VALUES  (1001,'yy',2)  
    insert into #EmployeeRegioncode  VALUES  (1001,'zz',3)  
    insert into #EmployeeRegioncode  VALUES  (1001,'xy',4)  
    insert into #EmployeeRegioncode  VALUES  (1002,'qq',1)  
    insert into #EmployeeRegioncode  VALUES  (1002,'rr',2)  
    insert into #EmployeeRegioncode  VALUES  (1002,'ss',3)  
    ---Target
    Create table #EmployeeDetails
    (EmployeeID int, Code1 varchar(10), Code2 varchar(10),Code3 varchar(10),Code4 varchar(10),Code5 varchar(10) , regioncode1 varchar(10),
    regioncode2 varchar(10),regioncode3 varchar(10),regioncode4 varchar(10))
    insert into #EmployeeDetails  VALUES (1000,'AA','BB','CC','','','xx','yy','zz','')  
    insert into #EmployeeDetails  VALUES (1001,'AAA','BBB','CCC','DDD','','xx','yy','zz','xy')  
    insert into #EmployeeDetails VALUES (1002,'AAAA','BBBB','CCCC','DDDD','EEEE','qq','rr','ss','')  
    SELECT * FROM  #Employee
    SELECT * FROM  #EmployeeCode
    SELECT * FROM  #EmployeeRegioncode
    SELECT * FROM  #EmployeeDetails
    Can you please help me to get the desired /targetoutput?  I have sql server 2008.
    Your help is greatly appreciated.

    select a.EmployeeID,b.code1,b.code2,b.code3,b.code4,b.code5,c.Reg1,c.Reg2,c.Reg3,c.Reg4 from
    #Employee a
    left outer join
    (select EmployeeID,max(case when [Order] =1 then Code else '' end) code1,
    max(case when [Order] =2 then Code else '' end)code2,
    max(case when [Order] =3 then Code else '' end)code3,
    max(case when [Order] =4 then Code else '' end)code4,
    max(case when [Order] =5 then Code else '' end)code5 from #EmployeeCode group by EmployeeID) b
    on a.EmployeeID=b.EmployeeID
    left outer join
    (select EmployeeID,max(case when [Order] =1 then RegionCode else '' end) Reg1,
    max(case when [Order] =2 then RegionCode else '' end)Reg2,
    max(case when [Order] =3 then RegionCode else '' end)Reg3,
    max(case when [Order] =4 then RegionCode else '' end)Reg4 from #EmployeeRegioncode group by EmployeeID) c
    on a.EmployeeID=c.EmployeeID
    Thanks
    Saravana Kumar C

Maybe you are looking for