SQL to convert rows with more than one columns to columns

Hi All,
I have a typical question here. As must have been in most of the recent databases, the attributes of a master table are put in a child table. So an SQL query will return multiple rows with each row having each attribute.
Eg: Object OBJ has 5 attributes - A, B, C, D, E. The tables would be
TABLE OBJ
======
OBJ_ID (PK) (Say ID1)
OBJ_COL1
OBJ_COL2
TABLE OBJ_CHILD
========
OBJ_CHILD_ID (PK)
OBJ_ID(FK)
ATTRIBUTE (The data will be A,B,C,D,E for each OBJ_ID)
ATTRIBUTE_VALUE (Value for each attribute. say 1,2,3,4,5)
Query : SELECT OBJ_ID, ATTRIBUTE, ATTRIBUTE_VALUE FROM OBJ < OBJ_CHILD where OBJ.OBJ_ID = OBJ_CHILD.OBJ_ID
This will return 5 rows as :
OBJ ATTRIBUTE ATTRIBUTE_VALUE
=== ======== =============
ID1 A 1
ID1 B 2
ID1 C 3
ID1 D 4
ID1 E 5
I need to return rows as follows:
ID1 A 1 B 2 C 3 D 4 E 5
Is this thing possible in SQL? Even with a function ? (Its a transpose but with two columns in every row)
Thanks,
Midhun.
P.S. I am on Oracle 10g.

Hi
user8830587 wrote:
... I need to return rows as follows:
ID1 A 1 B 2 C 3 D 4 E 5How many columns is that?
If it's 11 or 12 separate columns, then look for Pivot .
If it's 2 or 3 columns (where the last one is all the data from obj_child concatenated together), then look for String Aggregation .
Either can be done with any number of columns.
If you have a choice, you'll probably want to do string aggregation rather than pivot.
If you'd like help, post a little sample data (CREATE TABLE and INSERT statements) for both tables.
Also post the results you want from that data, clearly formatted to show the columns. When you post formatted text on this site, type these 6 characters:
\(all small letters, inside curly brackets) before and after each section of formatted text, to preserve spacing.
Edited by: Frank Kulash on May 14, 2010 6:26 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • PS2013 / SQL 2012 - A SQL Reporting Services Report with more than one filter connection looses connection in a site template

    Hi,
    I created in a sub site not linked to a project to become a site template. I inserted two SQL Reporting Services reports web part that require the same two dates for an interval and the name of the project in a page of the site and connected
    to three filters, two for date and one for text and I got the page below (only one of the reports shown).
    Look that all parameters needed by the report are linked to the filters above the report.
    Then I save the site as template with all contentes and assign it to the EPTs and create a new project or replace the site of existing project site. What I got is:
    Look that the filter connection of the dates are lost (in both reports) and the order of the filters changed.
    I deleted and retried to connect the filters in diferent order and language, but I did not get any success.
    The BI Central Data Connectivity resource is activated in the template site and in the site collection.
    Is there any solution for this?
    Best regards, Ricardo Segawa - Segawas Projetos / Microsoft Partner

    Hi,
    Correction: this happens only with "Date Filter" web part!
    Best regards, Ricardo Segawa - Segawas Projetos / Microsoft Partner

  • Error while running spatial queries on a table with more than one geometry.

    Hello,
    I'm using GeoServer with Oracle Spatial database, and this is a second time I run into some problems because we use tables with more than one geometry.
    When GeoServer renders objects with more than one geometry on the map, it creates a query where it asks for objects which one of the two geometries interacts with the query window. This type of query always fails with "End of TNS data channel" error.
    We are running Oracle Standard 11.1.0.7.0.
    Here is a small script to demonstrate the error. Could anyone confirm that they also have this type of error? Or suggest a fix?
    What this script does:
    1. Create table object1 with two geometry columns, geom1, geom2.
    2. Create metadata (projected coordinate system).
    3. Insert a row.
    4. Create spacial indices on both columns.
    5. Run a SDO_RELATE query on one column. Everything is fine.
    6. Run a SDO_RELATE query on both columns. ERROR: "End of TNS data channel"
    7. Clean.
    CREATE TABLE object1
    id NUMBER PRIMARY KEY,
    geom1 SDO_GEOMETRY,
    geom2 SDO_GEOMETRY
    INSERT INTO user_sdo_geom_metadata (table_name, column_name, srid, diminfo)
    VALUES
    'OBJECT1',
    'GEOM1',
    2180,
    SDO_DIM_ARRAY
    SDO_DIM_ELEMENT('X', 400000, 700000, 0.05),
    SDO_DIM_ELEMENT('Y', 300000, 600000, 0.05)
    INSERT INTO user_sdo_geom_metadata (table_name, column_name, srid, diminfo)
    VALUES
    'OBJECT1',
    'GEOM2',
    2180,
    SDO_DIM_ARRAY
    SDO_DIM_ELEMENT('X', 400000, 700000, 0.05),
    SDO_DIM_ELEMENT('Y', 300000, 600000, 0.05)
    INSERT INTO object1 VALUES(1, SDO_GEOMETRY(2001, 2180, SDO_POINT_TYPE(500000, 400000, NULL), NULL, NULL), SDO_GEOMETRY(2001, 2180, SDO_POINT_TYPE(550000, 450000, NULL), NULL, NULL));
    CREATE INDEX object1_geom1_sidx ON object1(geom1) INDEXTYPE IS MDSYS.SPATIAL_INDEX;
    CREATE INDEX object1_geom2_sidx ON object1(geom2) INDEXTYPE IS MDSYS.SPATIAL_INDEX;
    SELECT *
    FROM object1
    WHERE
    SDO_RELATE("GEOM1", SDO_GEOMETRY(2001, 2180, SDO_POINT_TYPE(500000, 400000, NULL), NULL, NULL), 'MASK=ANYINTERACT') = 'TRUE';
    SELECT *
    FROM object1
    WHERE
    SDO_RELATE("GEOM1", SDO_GEOMETRY(2001, 2180, SDO_POINT_TYPE(500000, 400000, NULL), NULL, NULL), 'MASK=ANYINTERACT') = 'TRUE' OR
    SDO_RELATE("GEOM2", SDO_GEOMETRY(2001, 2180, SDO_POINT_TYPE(500000, 400000, NULL), NULL, NULL), 'MASK=ANYINTERACT') = 'TRUE';
    DELETE FROM user_sdo_geom_metadata WHERE table_name = 'OBJECT1';
    DROP INDEX object1_geom1_sidx;
    DROP INDEX object1_geom2_sidx;
    DROP TABLE object1;
    Thanks for help.

    This error appears in GeoServer and SQLPLUS.
    I have set up a completly new database installation to test this error and everything works fine. I tried it again on the previous database but I still get the same error. I also tried to restart the database, but with no luck, the error is still there. I geuss something is wrong with the database installation.
    Anyone knows what could cause an error like this "End of TNS data channel"?

  • Master with more than one Detail

    Hallo,
    Does anybody know how to create master with more than one detail. i.e
    Employee as a master with the following details
    (Dependent, Education, Contract, Job History).
    thanks..
    Ribhi

    Ribhi,
    A master detail form typically consist of a master form and a tabular form for the detail records, i.e. you can edit your detail records on the same page as your master record. Since you can only have one tabular form per page, having multiple of these detail tabular forms, won't work. However you could instead create your master-detail form with the option of creating the detail as a read-only report, which would have an edit link on each detail row, that would take you to a form to edit each detail row individually. With this model, you could just add additional reports after the initial creating of the master-detail form.
    Regards,
    Marc

  • Function with more than one return value

    Hi
    Please let me know how to write a function with more than one return value and in what scenario should we go for this option.
    Thank you

    user12540019 wrote:
    Please let me know how to write a function with more than one return value and in what scenario should we go for this option.Yes. And the following is the correct approach (using OUT variables is not!) - you deal with the multiple values as a data structure. This example uses an custom (user-defined) SQL data type as the structure.
    SQL> create or replace type TXYcoord is object(
      2          x       number,                  
      3          y       number                   
      4  );                                       
      5  /                                        
    Type created.
    SQL>
    SQL>
    SQL> create or replace function fooCoordinate( someParam number ) return TXYCoord is
      2  begin                                                                         
      3          -- doing some kind of calculation using input parameters              
      4          --  etc..
      5
      6          -- returning the multiple return values as a proper data structure
      7          return(
      8                  TXYcoord( 0, 0 )
      9          );
    10  end;
    11  /
    Function created.
    SQL>
    SQL> -- selecting the data structure
    SQL> select
      2          sysdate,
      3          fooCoordinate(123)      as XY
      4  from       dual;
    SYSDATE             XY(X, Y)
    2010-02-01 08:49:23 TXYCOORD(0, 0)
    SQL>
    SQL> -- selecting the properties/fields of the data structure
    SQL> select
      2          sysdate,
      3          treat( fooCoordinate(123) as TXYcoord).x        as X,
      4          treat( fooCoordinate(123) as TXYcoord).y        as Y
      5  from       dual;
    SYSDATE                      X          Y
    2010-02-01 08:49:23          0          0
    SQL>

  • Create a logical column with more than one data source

    I'm having a problem to create a logical column with more than one data source in Siebel 7.8.
    What I want to do is the union of 2 physical tables in one logical table.
    For example, I have a "local_clients" table and a "abroad_clients" table. What I want is to have a logical table "clients" with the client data from the 2 tables.
    What I've tried is dragging the datasources I need onto the logical column.
    However this isn't working because it only retrieves the data from the first data source.

    Hi!
    I think it is not possible to do this just by dragging the columns to the logical table. A logical table can have more than one source, but I think each column must have just one direct source column.
    I'm not sure, but maybe you should do the UNION SQL to get the data of the two tables. In the physical layer, when you create a new physical table, it's possible to set the "table type" as a "SELECT". I didn't try that, but it seems that it's possible to have the union table in the physical layer.
    Bye.
    Message was edited by:
    user578388

  • Error when trying to chat with more than one perso...

    I am getting an error when trying to chat with more than one person at a time.
    The message is like below:
    There has been an error while proccesing.
    Do you want to start debugging.
    Row: 0
    Error: No authorization
    Thank you in advance for assistance.
    Kind Regards
    Marcin
    Attachments:
    error.jpg ‏12 KB

    What is the version of Internet Explorer installed on your computer?
    In Internet Explorer go to Help -> About Internet Explorer.
    P.S. Please, don’t say that you are not using Internet Explorer. This is irrelevant. Skype depends on Internet Explorer.

  • Reports 9i Graphs with more than one query..

    Hello,
    I am converting my 6i reports to 9i reports. On my graph reports with more than one query, when I invoke the graph wizard it changes the value of the src to the wrong query automatically. When I run my report, I am getting the error REP-0069 Internal Error rwlib-1: REP-6219 Column (Column Name) not in given cursor hierarchy. Although it's a pretty easy fix to go into the graph settings in the property palette and change it back, it is extremely frustrating. Has anyone else ran into this problem and did you find a permanent fix?
    Thanks,
    Laura

    Hi Laura
    One workround would be to create a new query in the Data Model that includes desired fields, and then source
    chart to the new group.
    FYi, bug2527100 was filed on this issue and is already fixed. The fix would be available in 9i Reports 9.0.2.2 patch. Reports 9.0.2.2 patch is scheduled to be released on Mar 05 2003 (tentative date).
    Thanks
    The Oracle Reports Team

  • Is there a stereo bluetooth headset that can pair with more than one device at a time?

    Is there a stereo bluetooth headset that can pair, i.e. multipoint, with more than one device at a time?
    Are the MacBook and iPhone 4 capable of multipoint bluetooth technoloagy?
    The goal is for my wife to be able to watch her Korean TV soap operas on her MacBook and still receive a call on her iPhone 4 via a stereo bluetooth headset.
    I was looking at the Motorola S10-HD but after further review saw that it only pairs with one device at a time.
    Appreciate any and all input. My Googling has returned no results.
    Rick

    TeslasBB wrote:
    pairing my BB8330 with my blue tooth earphone(TM:jawbone) and my microsoft sync thats in my car simultaneously? if i pair with the car, will i have to pair my jawbone all over again?
    You can only pair one device at a time to your 8330, or any other phone for that matter.  The "pairings" are saved to the phone, you can use one or the other and you won't have to pair it again.  Once you turn your bluetooth device on and the phone is on, they will find each other again.
    Hope this helps,
    John
    Stevie Ray! 1954-1990
    ** Don't forget to resolve your post with the accepted solution.

  • Can I use a magic trackpad with more than one Mac at a time?

    I am attempting to pair a MTP with a second MacBook Pro.  So far I can't get system preferences to find the MTP.
    I am wondering whether the MTP can be paired with only one Mac at a time, and that this is why my MBP won't find it.
    The reason I am thinking this is because the little booklet that comes with the MTP says 'after you pair your MTP with a Mac, you can pair it again with a different Mac.  To do this, you first remove the existing pairing and then pair the trackpad again'.
    Can anyone advise, please?
    If it can be paired with more than one MBP at a time, any suggestions why my system preferences search for the MTP is not producing any results?
    Thanks

    Yes, your keyboard, mouse or trackpad can be paired with multiple Macs.  You can even have multiple keyboards, mice or trackpads paired with one Mac.  The caveat is that the device can only be connected to one Mac at a time.  The device can't be paired or connected with a Mac while it's currently connected to another.
    Pairing a device with 2 Macs will be troublesome if the Macs are located within 33 ft of each other.  The device will connect with the first available paired Mac and then unavailable to the second.   If the Macs are located outside the 10meter range, it's quite easy to power off the keyboard (forcing a disconnect) then walking the keyboard to Mac 2 and powering the keyboard on.   I do this with a keyboard from my iMac to a Mac Mini in another room.
    Captfred

  • Send email from SAP with more than one attachment

    Hi all,
    How can i send email with more than one attachment and different types of document(doc,pdf,etc.) from SAP to external?
    Besr regards,
    Munur

    Hi,
    I use :
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    the main problem with different attachemts is to genereate the packing_list.
    the packing list is a kind of description of the data table... where ist the start  of an image, end, size...
    "Creation of the entry for the compressed attachment
            objpack-transf_bin = 'X'.                    " it could be an image
            objpack-head_num = lv_head_num_count .  " inital 1 each att  add 1
            objpack-head_start = 1.                     " fix
            objpack-body_start = gv_startnum.    " table with attachments  1. line one
            objpack-body_num = tab_lines.          " how many lines are in the table of attachment
            objpack-doc_size = tab_lines * 255.   " size of the  attachment...
           objpack-doc_type = lv_typ . " 'JPG'.
            objpack-obj_name = 'ATTACHMENT'.
            objpack-obj_descr = lv_stripped_name  " name of the JPG
       APPEND objpack.
       APPEND LINES OF lt_goscontent TO gt_maildata.  " data Table...
    bestreg
    robert

  • By subscribing to Creative Cloud(Photoshop and Lightroom), does it come with more than one license, and is it possible to install it on both Windows and Apple(if it comes with two licenses)? Thank you.

    By subscribing to Creative Cloud(Photoshop and Lightroom), does it come with more than one license, and if it does, is it possible to install on both Windows and Apple's OX? Thanks.

    A Cloud subscription provides for installing working installations on two machines.  You can have mixed operating systems (both Windows and Apple's OX).

  • When I import a cd with more than one artist iTunes separates each individual artist - how do I get it to show the album as a whole rather than individual artist?

    When I import a cd with more than one artist itunes shows each artist's song separately and won't group the album as a whole - this is incredibly frustrating something that Windows media player doesn't do. Does anyone have a simple cure for this annoyance?

    Generally all you need to do is fill in an appropriate Album Artist. For more details see my article on Grouping Tracks Into Albums, in particular the topic One album, too many covers.
    tt2

  • Can you sign in with more than one apple id on an iPad?

    Can you sign in with more than one apple id on an iPad?

    Only one account can be signed in at a time (via Settings > Store), and if you turn on automatic downloads and/or download past purchases from an account then you risk tying the iPad to that account for 90 days : http://support.apple.com/kb/HT4627

  • Why is all my icloud account linked with more than one apple id?

    why is my iphone 5 merged with more than one account?

    What do you mean by "merged with more than one account" and "linked with more than one Apple ID"?  What exactly are you seeing on your phone?

Maybe you are looking for

  • When opening Facebook, Safari closes with error message

    It has happened for two days now.  I have restarted the computer, cleared the cache and it still happens.  The error message is below.   All other websites work normally - it only happens in Facebook.  I would appreciate someone's assistance, PLEASE!

  • In aperture 3 and Iphoto '09, import from show iphoto browser doesn't work

    when I choose  Import/Show Iphoto Browser, I get the browser blank, with the sentence "no items to show". What to do?

  • Output decimal number through GPIB or VISA

    I was wondering if it is possible to output a decimal number, as in not a string, through the GPIB or VISA commands. I am trying to communicate with a machine that I think wants to get a number, and can't understand what I am sending when it is in a

  • ZSAPLINK for Object type = CLAS is not working

    Dear Experts, ZSAPLINK for Object type = CLAS is not working. On executing by selecting Export Object to Slinkee with Object type = CLAS and class name, It is giving the dump which is shown in below snapshots. Pls guide me how to resolve this error.

  • How can I format my firmware?

    Hi, I am going to sell my iMac in cex. Unfortunately, they said my firmware is in Chinese. Therefore, is that possible to format the firmware to English and how? Thank you. My iMac is 12.1 Boot ROM Version IM121.0047.B1F SMC Version (system) 1.71f21