Rows to Coulmns

hi guys,
I am having trouble converting rows to columns. Read a few articles on Pivot and Decode but still could not figure it out.
For eg.
Table info
Unit_no.                       Unit_id
001                                xyz
002                                ABC
003                                ABC
004                                XYZ
005                                XYZI would like the output to be
XYZ                                  ABC
001                                     -    
-                                       002
-                                       003
004                                      -
005                                      -
005Thanks

Hi,
Anita.I wrote:
hi guys,
I am having trouble converting rows to columns. Read a few articles on Pivot and Decode but still could not figure it out.
For eg.
Table info
Unit_no.                       Unit_id
001                                xyz
002                                ABC
003                                ABC
004                                XYZ
005                                XYZI would like the output to be
XYZ                                  ABC
001                                     -    
-                                       002
-                                       003
004                                      -
005                                      -
005
I assume there's a mistake above, and you really only want one row of output that says 005.
Here's one way to do that:
SELECT       CASE (WHEN UPPER (unit_id) = 'XYZ' THEN unit_no END)     AS xyz
,       CASE (WHEN UPPER (unit_id) = 'ABC' THEN unit_no END)     AS abc
FROM       info
ORDER BY  unit_no
;Your problem is a little different from most pivot problems. In most of the examples you've seen, the result set probably had fewer rows than the original table. In your case, it seems like you want to keep the same number of rows, so you don't need the aggregate functions (such as MIN) or GROUP BY that (I assume) you saw in your reading.
If you did have multiple rows in your table with the same unit_no, but you only wanted the results to have one row per unit_no, then you would have a more conventional-looking pivot:
SELECT       MIN (CASE (WHEN UPPER (unit_id) = 'XYZ' THEN unit_no END))     AS xyz
,       MIN (CASE (WHEN UPPER (unit_id) = 'ABC' THEN unit_no END))     AS abc
FROM       info
GROUP BY  unit_no
ORDER BY  unit_no
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002}

Similar Messages

  • Vb Macro for converting rows into coulmns

    Hi Experts--
    Can any one plz give me the code to write a VB macro for displaying the input values in the column wise.
    By default we are getting the input values in a row between the navigation block and the result area in a report.
    My requirement is to display this in the second sheet but column wise.
    Any how iam displaying this horizantally (row wise)in the second sheet of a workbook but i need in the column wise.
    Thanks & Regards,
    Rambo

    Hi Rambo,
    You can use the following simplified code as a basis for your own.
    It takes values in B-column of  RowNo column, parses it and inserts separate values into the 2nd worksheet.
    Set value of RowNo and RowNo2 and try it.
    Sub SAPBEXonRefresh(queryID As String, resultArea As Range)
    Dim ws1 As Worksheet, ws2 As Worksheet, J As Integer
    Dim RowNo As Integer, RowNo2 As Integer, CellValue As String, delim As String
    Dim StartPos As Integer, EndPos As Integer
    RowNo = 6   'Row number with filter values
    RowNo2 = 5  'Row number in the 2nd sheet
    delim = "," 'Delimiter
    Set ws1 = ThisWorkbook.Worksheets("SHEET1")
    Set ws2 = ThisWorkbook.Worksheets("SHEET2")
    CellValue = ws1.Cells(RowNo, 2)
    StartPos = 1
    J = 1
    Do While J < Len(CellValue)
        If Mid(CellValue, J, 1) = delim Then
            EndPos = J - 1
            ws2.Cells(RowNo2, 1) = Mid(CellValue, StartPos, EndPos - StartPos + 1)
            RowNo2 = RowNo2 + 1
            StartPos = J + 1
        End If
        J = J + 1
    Loop
    ' The last value
    ws2.Cells(RowNo2, 1) = Mid(CellValue, EndPos + 2)
    End Sub
    Best regards,
    Eugene

  • Error when Converts rows to columns dynamically in clob data type

    Hi
    I am using below pl/sql statement
    SELECT NO,
    MAX (DECODE (NAME, 'A', VALUE1, NULL)) AS A,
    MAX (DECODE (NAME, 'B', VALUE1, NULL)) AS B,
    MAX (DECODE (NAME, 'C, VALUE1, NULL)) AS C,
    MAX (DECODE (NAME, 'D', VALUE1, NULL)) AS D
    FROM ( SELECT NO,
    RTRIM (
    XMLAGG (XMLELEMENT (E, VALUE || ',')).EXTRACT ('//text()').
    GETCLOBVAL (),
    VALUE1,
    NAME
    FROM DA
    while i am execute for varchar type its as i expected. when i tried with clob data type i am getting follwoing error.
    ORA-00932: inconsistent datatypes: expected - got CLOB
    can any one pleas me?
    thanks
    Nagarajan.V

    Nagarajan Venu wrote:
    Thanks for your reply
    This is scenario.
    This is my table
    NO--name--value
    1--A--ASDF
    2--B--IOP
    all columns are clob type and i want the output like below.
    No--A
    1--ASDF
    2--IOP
    i just want to convert all rows to coulmns(clob type) dynamically.I don't get how you got that output from the data? What happened to "B"?
    Please post a suitable example and expected output using create table and insert statements as well as giving your database version and using {noformat}{noformat} tags as detailed in the FAQ: {message:id=9360002}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Exporting data in rows and columns and loading in RDBMS

    <p>I have a scenario wherein i want to export data from HyperionEssbase in <b>rows and coulmns</b> and <b>load it into</b><b>RDBMS</b>. I can load data into RDBMS using informatica if theflat file exported is in form of rows and columns.But when i exportthe file using Hyperion Essbase 9 i get it in from of alldimensions and then the fact value which is not how i want. I wantdata in relational from in flat file itself(row,column).</p><p>Looking forard to your suggestions..Thanks in advance..</p>

    <p>Thanks <b>willjordan</b> and <b>twakim</b> for yoursuggestions..</p><p> </p><p>I tried both the techniques and both worked...</p><p>With reference to the technique suggested by <b>twakim</b> , I was able to use that in Hyperion Essbase 9..But in myreal scenario the cube is in Hyperion Essbase 6.5.4.2..Can i usethis Custom defined functions in Hyperion Essbase 6.5.4.2..and ifso how as there is no concept of Analytical server there???</p><p> </p><p>Please help me in this issue???<br></p>

  • Custom Components not Visible in the Flex Design

    Hi
        I am trying to create a Flex Application to consume a Web service.
         Which DataGrid can i use to get the list of data at runtime.
         The Datagrid component which is available  under Controls in the design is displaying 3 columns and 3 rows by default. But if i use this UI element no.rows and coulmns cannot be changed at runtime.
    So could anybody advice me which datagrid can be used?
    By defalult Flex design has Controls, Layout, Navigators, Charts components
    Could anybody tell me whats Custom Component in the design. becoz i cannot see any of the components under Custom folder.
    Is it a custom developed one or is it a Default like other components ?
    How do I get these components  Customer DataGrid, Video Chat, Yahoo Search, Countries By Group etc.
    Please guide me...
    Thanks & Regards
    Sireesha.
    Edited by: sireesha esukapalli on Dec 1, 2008 1:06 PM
    Edited by: sireesha esukapalli on Dec 1, 2008 1:17 PM

    Hi Daniel,
        Could you please check the below code in MXML.
        I am getting the error as Unexpected paramater "CustomerNo" not found in input arguments.
       What node should be given under <request> tag ? Is it can be any xml node related to customer no? or anyother thing?
        <mx:WebService id="WSCust"
         wsdl="http://ctsintcosnw4.cts.com:8000/sap/bc/srt/rfc/sap/zws_custinfo?sap-client=812&wsdl=1.1 "
        showBusyCursor="true"
         fault="Alert.show(event.fault.faultString)"
         result="onCustResult(event)"
              >
    <mx:operation name="ZBAPI_CUSTOMER_DETAIL2">
         <mx:request>
         <CustomerNo>
              {Cust_no.text}
         </CustomerNo>     
         </mx:request>
    </mx:operation>
    </mx:WebService>
    <mx:Script>
         <![CDATA[
    private function Getcust_data():void
    WSCust.getOperation("ZBAPI_CUSTOMER_DETAIL2").send();
         ]]>
    </mx:Script>
    <mx:Label  text="CustomerNo"  id="lblcustno" />
         <mx:TextInput id="Cust_no" />
    <mx:Button  id="btn_custno" label="Display Customer General Data" click="Getcust_data()" />
    Regards
    Sireesha.

  • How concatenate date and array to write in excel?

    Hello
    I have a problem to concatenate a date array and numeric array. can you help me?
    I want save Measurement of a sensor with save time in an excel (row 1 column1 save date and row 1 coulmn : save sensor data). but I cant save these two value seperatly(my clocks cant do it). now, I want concatenate them at first and then save them. is it possible?
    Best Regards
    Solved!
    Go to Solution.
    Attachments:
    concatenate.jpg ‏82 KB

    Try the attached.  You'll understand it as soon as you see it.  If not, shout.
    Attachments:
    write_to_file.vi ‏8 KB

  • How to create report from report painter??

    Hi,
    how to create report from report painter?? from transaction code GRR1

    Select the library that you want report to create.  GRR1
    You select what to list in coulumns and what to lisr in rows. You could select characteristics or key figures.
    You can use variable both in defininig row and coulmn or in general selection.
    You can also use sets as variable or as constant. These sets can be your master data groups or sets in GS02.
    You can use formulas.

  • Smartform problem urgent

    When printing a performance review if a bullet point or number is used can a new line be created in smartforms.
    what is the option for it.
    i will award ur effort.

    Hi ,
    Correction to rpevious answer
    create a template and create three text under template containing
    1.PO is created.
    2.PR is released.
    3.details of purchase order is displayed.
    assing first text to template row 1 coulmn 1
    assing second text to template row 2 coulmn 1
    assing third text to template row 3 coulmn 1 .
    regards

  • Can't Center Table {Scree shots Included}

    Hey there, I am trying to center a table within my main content area,  As you can see in the screen shots bellow, I have given the table the align="center" attribute.  I also tried setting bodyArea div margin left and right to Auto to no avail.  I even droped another class div inside the bodyArea with the same auto margin, again nothing.   The table dose Center in Dreamweaver but none of the browsers.
    This is the browser view, as you can see the table is pushed to the left wall.
    Ok Im going to push my luck here with a second question, you can see what I am trying to do in the table bellow.  All these tables are already complete in Microsoft works.  But I can't seem to cut and paste into Dreamweaver table as it just pastes everything into the one cell.  So I am cutting and pasting every individual cell, yes 17 tables, over 100 rows, 5 coulmns.  So as you can Imagine it is going to take forever.  So if any1 reading this can help, you will save me days of work.  Thank you

    Give the table and ID, set a width and then margins for centering... eg:  Same as if you were centering a div.
    CSS:
    #maintable {
    width: 980px;      /* change width as required here */
    margin: 0 auto;
    HTML:
    <table id="maintable">
    that should work, unless there is something else in the code that will cause this to fail.
    PS:  If you need to add any padding on the cells, add the style to the <td>
    #maintable td {
    padding: 4px;

  • How can we display 2 rows in a single row with new coulmn names?

    Hi,
    I have a requiment as shown below.
    ME A_END Z_END
    1 aaaa
    2 zzzzz
    I need the above data in the below format.
    A_ME Z_ME A_END Z_END
    1 2 aaaa zzzzz
    How can we achive this?

    user6755466 wrote:
    Hi Alex,
    Thanks for your quick response.
    Actually the coulmns ME_ID, A-END, Z-END, etc doesn't have fixed values as you hard coded with values (e.g., 1, 2) in your query.One way is to assign a "row number" to each row and then pivot using the known row numbers of 1, 2 ... etc.
    Example:
    SQL> ed
    Wrote file afiedt.buf
      1  with test as
      2  (
      3  select 3 a_end, 'aaaa ' z_end from dual union all
      4  select 5 a_end, 'zzzzz' z_end from dual
      5  )
      6  select max (decode (rn, 1, a_end)) a_me
      7       , max (decode (rn, 2, a_end)) z_me
      8       , max (decode (rn, 1, z_end)) a_end
      9       , max (decode (rn, 2, z_end)) z_end
    10  from (select a_end, z_end
    11              ,row_number() over (order by a_end, z_end) as rn
    12*       from test)
    SQL> /
          A_ME       Z_ME A_END Z_END
             3          5 aaaa  zzzzz
    SQL>Here, the values are 3 and 5, but they are assigned a row number based on the order of them and then the decode uses that row number to pivot them.
    Of course, as everyone else has pointed out, the best place to be doing this is in a dedicated reporting tool. SQL is not the best of places to pivot data for reporting purposes.

  • How to display the comma separeated values in a row in the form of coulmns?

    Hi,
    I have a table as shown below.
    Table name: Projs
    Project_Id Associates_List
    proj1 2,3,4,5
    proj2 2,5,1
    We are looking at moving this data into a normalized format as shown below.
    Project_Id Associates_List
    proj1 2
    proj1 3
    proj1 4
    proj1 5
    proj2 2
    proj2 5
    proj2 1
    How can we achieve this?
    If anybody knows, please provide the soultion.

    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'proj1' as proj_id, '2,3,4,5' as asoc_list from dual union all
      2             select 'proj2', '2,5,1' from dual)
      3  -- END OF TEST DATA
      4  select proj_id, asoc
      5  from (
      6        select proj_id
      7              ,regexp_substr(asoc_list, '[^,]+', 1, rn) as asoc
      8        from   t
      9              ,(select rownum rn
    10                from dual
    11                connect by rownum <= (select max(length(regexp_replace(asoc_list,'[^,]')))+1
    12                                      from t
    13                                     )
    14               ) x
    15       )
    16  where asoc is not null
    17* order by 1, 2
    SQL> /
    PROJ_ ASOC
    proj1 2
    proj1 3
    proj1 4
    proj1 5
    proj2 1
    proj2 2
    proj2 5
    7 rows selected.
    SQL>Edited by: BluShadow on Oct 29, 2009 3:09 PM
    reworded a.s.s. so that profanity checker doesn't complain.

  • Coulmn heading in several rows using 'Delimited' option

    Hello folks -- I am using Oracle Reports 6i and when generating a File to 'Delimited' to produce a Text file, I am getting the Column headings repeated in every row. So, all the columns are being produced in every row and every column and then data is being produced.
    My ultimate goal is to open the Text file in Excel and save it as an Excel file.
    I noticed that Oracle Reports 9i has the option of 'Delimited Data' which works fine. Is there a work around in Reports 6i? Maybe by using Format Triggers?
    Any help is greatly appreciated.
    Thanks

    I found the problem.
    Since the headings are also in a Repeating Group, the Heading were appearing on every row along with the data. Here is what you should do as its working for me:
    1. Remove the Headings from the Layout completely.
    2. Add the Headings in the SQL Statements and do a UNION with the Main Query. Add a dummy column at the end for the Ordering BY so the row with the headings show up on the top row followed by the data.
    3. Don't include the order_id column in the Layout.
    Hint: Do a TO_CHAR for every column in the Main Query as the Headings will be Character field
    Thanks!
    Edited by: Roxyrollers on Sep 24, 2012 4:00 PM

  • How to add a checkbox coulmn to my Data Grid row?

    Dear All ,
    I have a Data Grid which have lets says 6 columns. I want to add anew column which allow the user to select it or not. Meaning if the user select the box a hack will be shown.
    I want to you this coz I have a function which send an email to the user if the line (Invoice line) if selected. Now if there is more than one invoice (Line) I want the user to first select the checkbok and send press the send function button.
    Later on I will create a loop in the Send function which will only send mails if the line check box is checked.
    Would you please help me :)
    Ps: I am using ligth switch 2008   (C#)
    Thanks,
    Zayed

    Hello Zayed
    I would recommend that you read through this brilliant article by
    Paul van Bladel here or even look at a post on
    this forum by Sven Elm. I have looked at and followed these in the past and it works perfectly.
    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

  • Drill Down between 2 stacked column chart with multiple rows.

    Hi,
    Can anyone please help me.
    1) i have to create stacked column chart with Region and cout of calls for previous 3 quarters.
    2) the 2nd stacked column should display the priority with the count of calls for the respective selection of region on the 1st chart..
    to achieve this,
    i'm using 2 stacked column charts and 1 lebel baseb menu.
    from this i can able to get the drill down from label based menu to 2nd stacked column chart but i couldn't able to done the same from 1st stacked coumn chart.
    Becoz my data is multiple row for each quarter.
    please suggest me to achieve the drill down between 2 stacked column charts.
    assume that my data like below.:
    coulmns for 1st stacked column chart : Region, Q2,Q3 &Q4
    Region                Q2                Q3               Q4
    Other              3658              3497               497
    NA - North
    America                3               3               1101
    APJK     1     4     597
    UK               324
    EMEA North     1     1     288
    CORPORATE     1     5     215
    LA -
    Latin America1     2     208
    EMEA     1          199
    EMEA South     1     1     169
    Coulmns for 2nd coumn chart:  Region, Priority, Q2,Q3,Q4 ()which is derived from 1st table.
    Region     Priority     Q2     Q3     Q4
    Other     D: End of Next Day     1568     1613     239
    Other     C: End of Day     983     893     119
    Other     A: 2 Hour     631     610     70
    Other     B: 4 Hour     396     318     56
    NA -
    North AmericaD: End of Next Day     2     2     514
    APJK     D: End of Next Day          3     297
    NA -
    North AmericaC: End of Day               284
    NA -
    North AmericaA: 2 Hour     1          170
    UK     D: End of Next Day               157
    APJK     C: End of Day     1     1     152
    Other     E: 3 - 5 Business Days     68     58     13
    EMEA North     D: End of Next Day          1     136
    CORPORATE     D: End of Next Day          4     107
    NA - North America     B: 4 Hour          1     104
    LA - Latin America     D: End of Next Day     1     1     86
    EMEA     D: End of Next Day               86
    UK     C: End of Day               85
    APJK     A: 2 Hour               79
    EMEA South     D: End of Next Day               72
    EMEA North     A: 2 Hour               69
    EMEA North     C: End of Day               56
    APJK     B: 4 Hour               55
    EMEA     C: End of Day     1          53
    LA - Latin America     C: End of Day               54
    UK     A: 2 Hour               49
    EMEA South     C: End of Day     1          44
    CORPORATE     A: 2 Hour          1     43
    CORPORATE     C: End of Day               44
    LA - Latin America     A: 2 Hour          1     42
    EMEA South     A: 2 Hour          1     32
    EMEA     B: 4 Hour               30
    UK     B: 4 Hour               30
    EMEA     A: 2 Hour               27
    EMEA North     B: 4 Hour     1          26
    NA -
    North AmericaE: 3 - 5 Business Days               25
    LA - Latin America     B: 4 Hour               23
    EMEA South     B: 4 Hour               20
    CORPORATE     B: 4 Hour               17
    APJK     E: 3 - 5 Business Days               13
    Other     F: 6 - 10 Business Days     6     4     
    Other     G: 11 - 20 Business Days     6     1

    Hi Srinivas,
    I'm using label based menu "filterd rows" only but i couldn't bind the drill down with the 1st stacked column chart.
    for mor details:
    1) i'm having 2 stacked coumn charts & 1 lebel based menu but eventhough i couldn't able to achieve.
    if i select the lebel based values then the 2nd stacked column charts is giving detailed valus but if i keep my mouse on the 1st stacked column chart the there is no changes on the 2nd chart..
    somewhere i'm mising the binding data between 1st stacked coumn chart & lebel based menu on drill down part.
    Becoz i'm having multiple rows. so can you please try your and send me the xlf file using your concept.

  • Combine two resultset sidebyside in coulmn using mdx

    hi i am new to mdx,
    i want to combine two select statement resultset (side by side like union) using mdx query,please any body help me to solve this query
    first query:
     SELECT
    { [Last Year] }
    ON COLUMNS,
     { {[Location].[Location].&[7], [Location].[Location].&[12], [Location].[Location].&[11],
    [Location].[Location].&[19], [Location].[Location].&[17], [Location].[Location].&[16],
    [Location].[Location].&[9], [Location].[Location].&[18] },{[Location].[Location].[All]}}
    ON ROWS
    FROM [Cube1]
    WHERE ( [Measures].[Labour %] )
    here [Last Year] is a calculated set
    {STRTOMEMBER("[Date].[Month].&["+ cstr(year(now())-2) +"-11-01T00:00:00]"):
            (STRTOMEMBER("[Date].[Month].&["+ cstr(year(now())-1) +"-10-01T00:00:00]"))}
    2nd query:
    WITH MEMBER [Measures].[Budget ] AS IIF(avg([Last Year],IIF(([Measures].[Budget]>0),[Measures].[Budget],null)),
                                            avg([Last Year],IIF(([Measures].[Budget]>0),[Measures].[Budget],null)),0.00),
    MEMBER [Measures].[YTD] AS IIF(avg([Last Year], IIF(([Measures].[Labour %]>0),[Measures].[Labour %],null))<>null,
                                  avg([Last Year], IIF(([Measures].[Labour %]>0),[Measures].[Labour %],null)),0.00),
    FORMAT_STRING = "Standard",
    BACK_COLOR = CASE WHEN [YTD] = 0  THEN /*White*/16777215 /*White*/  
    WHEN [YTD] <= [Measures].[Budget ] THEN 65408
         WHEN [YTD]<= [Measures].[Budget ] +5 THEN 65535
         WHEN [YTD]> [Measures].[Budget ] +5 THEN 255
    END,
    VISIBLE = 1
    SELECT
    {  [Measures].[YTD], [Measures].[Budget ] }
    ON COLUMNS,
    { { [Location].[Location].&[7], [Location].[Location].&[12], [Location].[Location].&[11], [Location].[Location].&[19], [Location].[Location].&[17], [Location].[Location].&[16], [Location].[Location].&[9], [Location].[Location].&[18]
    },{[Location].[Location].[All]} }
    ON ROWS
    FROM [Cube1]
    here   ==> [Measures].[YTD], [Measures].[Budget ] are calculated member
    i want result like in
    coulmns===> ytd,budget,nov,dec,jan,feb.,,,,,,,,,,out
    rows ====> are only locations and total(average of all locations)
    please guide me to get solution like mdx query

    Hi Vsp,
    According to your description, you want to create a calculated member to combine two members, and then set it as Default member, right?
    In SQL Server Analysis Services, we can use the script below to create a calculated members.
    create member currentcube.[Date].[Day of Week].[weekend]
    as
    {[Date].[Day of Week].&[6],[Date].[Day of Week].&[7]
    Every attribute in a dimension in Microsoft SQL Server Analysis Services has a default member, which you can specify by using the
    DefaultMember property for an attribute. This setting is used to evaluate expressions if an attribute is not included in a query. Please refer to the link below to see the detail information about specify a default member.
    http://technet.microsoft.com/en-us/library/ms174822(v=sql.105).aspx
    Regards,
    Charlie Liao
    TechNet Community Support

Maybe you are looking for

  • Linking two fields in a dictionary view to the same field

    My DBA asked me if I knew how to do this without resorting to ABAP code, and I said I'd ask you guys over here. A customer wants a view on several tables.  Vendor name from LFA1 is one of the columns in the view. He has two other columns in the view

  • PIVOT sql help

    Hi again I need some PIVOT sql help In this query: SELECT SUM([RATES]) as RATES ,SUM([CONVERSION])as CONVERSION FROM REPORTING outputs RATES CONVERSION 23 234 How would change this query to display a table like: Name Amount RATES 23 CONVERSION 234 Ke

  • Mapping : Complex Structured Source to JDBC receiver structure

    Hello... We have a source structure as <?xml version="1.0" encoding="UTF-8"?> <ns0:MTO_Corporate xmlns:ns0="http://axis.com/authorization">    <Details>       <Corporate_Details> ---------- (occurence 1 to n)          <ID/>          <Name/>         

  • System.getProperty()

    Hi all, i am able to read the system property defined using -D in the command line.but i don't know, how to read a property from the properties file. what should be the exact format of the properties file. can u pls give me a sample properties file ,

  • My I Tunes Password is not taken in Clash of clans Shop. it says wrong?

    my I Tunes Password is not taken in Clash of clans Shop. it says wrong?