Flattening the hierarchial data

Hi,
I have the data in this format
ID        NAME         ParentID
CV1      CV1NAME      CV
CVX1    CVX1NAME    CV1
CVXX1  CVXX1NAME  CVX1
CV2      CV2NAME     CV
CVX2    CVX2NAME    CV2
CVXX2  CVXX2NAME  CVX2
How can i flatten this data into this format
CVID    CVNAME     CVXID   CVXNAME   CVXXID   CVXXNAME
cv1        cv1name  cvx1        cvx1name    cvxx1     cvxx1name
cv2        cv2name  cvx2        cvx2name    cvxx2     cvxx2name

DECLARE @table TABLE (ID varchar(10), NAME varchar(20), ParentID varchar(10))
INSERT INTO @table (ID, NAME, ParentID) VALUES
('CV1', 'CV1NAME', 'CV'),
('CVX1', 'CVX1NAME', 'CV1'),
('CVXX1', 'CVXX1NAME', 'CVX1'),
('CV2', 'CV2NAME', 'CV'),
('CVX2', 'CVX2NAME', 'CV2'),
('CVXX2', 'CVXX2NAME', 'CVX2')
SELECT
t0.ID AS CVID,
t0.NAME AS CVNAME,
t1.ID AS CVXID,
t1.NAME AS CVXNAME,
t2.ID AS CVXXID,
t2.NAME AS CVXXNAME
FROM
SELECT ID, NAME, RIGHT(ID, 1) AS Num
FROM @table
WHERE ID LIKE 'CV[1-9]'
) AS t0
FULL JOIN
SELECT ID, NAME, RIGHT(ID, 1) AS Num
FROM @table
WHERE ID LIKE 'CVX[1-9]'
) AS t1 ON t1.Num = t0.Num
FULL JOIN
SELECT ID, NAME, RIGHT(ID, 1) AS Num
FROM @table
WHERE ID LIKE 'CVXX[1-9]'
) AS t2 ON t2.Num = t0.Num
A Fan of SSIS, SSRS and SSAS

Similar Messages

  • How to delete the Hierarchy data from Infoobjects.

    How to delete the Hierarchy data from Infoobjects. In my case I had 300 records in the corresponding table of info object.
    When i was trying to delete the hierarchy data, I am getting error message. "Some master data not deleted". Can any one tell me to delete all these records by using a program.

    Hi
    Go to SE11 and enter the hierarchy table name.
    /BIC/H....(infoobject name)...and execute the table and select table entry and delete all....
    Thanks
    TG

  • How to write SQL query to flatten the hierarchy

    Hi,
    I have person table which has recursive hierarchy and I wish to flatten it upto 5 levels.
    I am using Oracle10g and I have written following query to flatten the hierarchy
    SELECT
    ID,
    level lvl,
    REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 1) AS level_1,
    REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 2) AS level_2,
    REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 3) AS level_3,
    REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 4) AS level_4,
    REGEXP_SUBSTR (SYS_CONNECT_BY_PATH (fname||' '||lname, '/'), '[^/]+', 1, 5) AS level_5
    FROM cmt_person
    CONNECT BY manager_id = PRIOR id
    and level<=5
    The person table have more than a million records.
    Here I am getting the correct output but this query is taking a lot of time to run.
    I am looking at a SQL query without use of connect by to get the required output.
    To recreate the issue, you can use this query in HR schema of Oracle and use Employees table.
    Any help would be greatly appreciated.
    Thanks,
    Raghvendra

    I tried to rewrite the query without using regular expression and connect by. Here is the code:
    SELECT
    cmt_person.id ,
    cmt_person.fname as mgr1,
    case when cmt_person2.manager_id=cmt_person.id then (cmt_person2.fname ) end as mgr2,
    case when cmt_person3.manager_id=cmt_person2.id then (cmt_person3.fname ) end as mgr3,
    case when cmt_person4.manager_id=cmt_person3.id then cmt_person4.fname end as mgr4,
    case when cmt_person5.manager_id=cmt_person4.id then cmt_person5.fname end as mgr5
    FROM
    cmt_person,
    cmt_person cmt_person2,
    cmt_person cmt_person3,
    cmt_person cmt_person4,
    cmt_person cmt_person5
    WHERE
    cmt_person2.manager_id(+)=cmt_person.id and
    cmt_person3.manager_id(+)=cmt_person2.id and
    cmt_person4.manager_id(+)=cmt_person3.id and
    cmt_person5.manager_id(+)=cmt_person4.id
    order by 2,3,4
    I got following output:
    emplo000000000200100     Bobby     Khasha     Rahul     Rajesh     
    emplo000000000200099     Bobby     Khasha     Rahul     Ajay     
    emplo000000000200101     Bobby     Khasha     Rahul     Swati     
    emplo000000000200320     Bobby     Khasha     Rahul     Jinesh     
    emplo000000000201231     Bobby     Khasha     Test123          
    emplo000000000201230     Bobby     Khasha     User1_Domain          
    emplo000000000201227     Bobby     Khasha     User1_World          
    emplo000000000200104     Bobby     Khasha     Yitzik     Natalia     
    emplo000000000200103     Bobby     Khasha     Yitzik     Andrew     
    total 9 rows
    But this is partially correct output. I want output like this:
    emplo000000000200097          Bobby                    
    emplo000000000200087          Bobby     Khasha               
    emplo000000000200102          Bobby     Khasha     Yitzik          
    emplo000000000200103          Bobby     Khasha     Yitzik     Andrew     
    emplo000000000200104          Bobby     Khasha     Yitzik      Natalia     
    emplo000000000201227          Bobby     Khasha     User1_World          
    emplo000000000201231          Bobby     Khasha     Test123          
    emplo000000000201230          Bobby     Khasha     User1_Domain          
    emplo000000000200098          Bobby     Khasha     Rahul          
    emplo000000000200099          Bobby     Khasha     Rahul     Ajay     
    emplo000000000200100          Bobby     Khasha     Rahul     Rajesh     
    emplo000000000200320          Bobby     Khasha     Rahul     Jinesh     
    emplo000000000200101          Bobby     Khasha     Rahul     Swati     
    total 13 rows
    Do you know what I should do to get this output.
    Thanks,
    Raghvendra

  • How to read the hierarchy data from the same table using loop in AMDP method

    Hi All,
    We have a requirement to get the top partner from BUT050 table.
    Here the Top parent is nothing but the top most in the hierarchy of the partners from BUT050.
    Example:
    For partner 1234 (BUT050-PARTNER1) there is partner 3523(BUT050-PARTNER2) one level above
    For partner 3523(BUT050-PARTNER1)  there is partner 4544 (BUT050-PARTNER2) last level .
    so in this case for the partner 1234 the Top parent is 4544 .
    I have created AMDP Procedure method to get the top-parnet and below given is the logic implemented in AMDP method.
    Here i have implemented a recursive logic with the WHILE loop to get the top most hierarchy partner from the same table BUT050
    IV_Parent is the input partner and ev_top_parent is the output value.
    AMDP Procedure Method:
        DECLARE lv_date VARCHAR(8) := TO_VARCHAR (current_date, 'YYYYMMDD');
        DECLARE found INT := 1;
              iv_partner1 =  SELECT partner1 FROM but050
                              WHERE partner2 = iv_partner
                              AND reltyp = :iv_hierarchy
                              AND date_to >=  :lv_date
                              AND date_from <= :lv_date;
         WHILE found <> 0  do
           select partner1 into ev_top_parent from :iv_partner1;
                           iv_partner1 =  SELECT partner1 FROM but050
                           WHERE partner2 in ( select partner1 from :iv_partner1 where partner1 is not null)
                           AND reltyp = 'ZBP004'
                           AND date_to >= :lv_date
                           AND date_from <= :lv_date;
           select COUNT ( partner1 ) INTO found FROM :IV_PARTNER1;
        END WHILE;
    This method is working fine, but here it is only taking one single partner and getting the top parent as output.
    Now i would like to convert this mehtod so as to accept n number of partners (not one single partner) as input and should process each partner to get the top parent.
    Could anyone guide me how can i handle the given AMDP method further so as to work some how it is within another loop from other AMDP method.
    Thanks.
    Regards,
    Laxman.P

    Hi
    Go to SE11 and enter the hierarchy table name.
    /BIC/H....(infoobject name)...and execute the table and select table entry and delete all....
    Thanks
    TG

  • Flattening the xml data

    Hi,
    I have the following XML loaded in the xmltype column.
    <g1>
         <f1>A</f1>
         <g2>
              <f2>a</f2>
              <g3>
                   <f3>1</f3>
                   <f3>2</f3>
                   <f3>3</f3>
              </g3>
         </g2>
         <g2>
              <f2>b</f2>
              <g3>
                   <f3>5</f3>
                   <f3>6</f3>
                   <f3>7</f3>
              </g3>
         </g2>
    </g1>
    From the above xml, how to get the following result,
    f1 f2 f3
    ===========================
    A     a 1
    A     a 2
    A     a 3
    A     b 5
    A     b 6
    A     b 7
    Thanks.

    SQL> var test varchar2(256)
    SQL> --
    SQL> begin
    2 :test := '<g1>
    3 <f1>A</f1>
    4 <g2>
    5 <f2>a</f2>
    6 <g3>
    7 <f3>1</f3>
    8 <f3>2</f3>
    9 <f3>3</f3>
    10 </g3>
    11 </g2>
    12 <g2>
    13 <f2>b</f2>
    14 <g3>
    15 <f3>5</f3>
    16 <f3>6</f3>
    17 <f3>7</f3>
    18 </g3>
    19 </g2>
    20 </g1>';
    21 end;
    22 /
    PL/SQL procedure successfully completed.
    SQL> select xmltype(:test).extract('/*')
    2 from dual
    3 /
    XMLTYPE(:TEST).EXTRACT('/*')
    <g1>
    <f1>A</f1>
    <g2>
    <f2>a</f2>
    <g3>
    <f3>1</f3>
    <f3>2</f3>
    <f3>3</f3>
    </g3>
    </g2>
    <g2>
    <f2>b</f2>
    <g3>
    <f3>5</f3>
    <f3>6</f3>
    <f3>7</f3>
    </g3>
    </g2>
    </g1>
    SQL> column F1 format A4
    SQL> column F2 format A4
    SQL> column F3 format A4
    SQL> --
    SQL> select extractvalue(xml,'/g1/f1') F1,
    2 extractvalue(value(g2),'/g2/f2') F2,
    3 extractValue(value(f3),'/f3') F3
    4 from (select xmltype(:test) as xml from dual),
    5 table (xmlsequence(extract(xml,'/g1/g2'))) g2,
    6 table (xmlsequence(extract(value(g2),'/g2/g3/f3'))) f3
    7 /
    F1 F2 F3
    A a 1
    A a 2
    A a 3
    A b 5
    A b 6
    A b 7
    6 rows selected.

  • Issue in Hierarchy data upload from R/3 for info object Product Hierarchy.

    Hi,
    I am trying to upload the hierarchy data from R/3 system for Info Object Product Hierarchy.
    Insted of business content info objects (0PRODH, 0PRODH1, 0PRODH2, 0PRODH3, 0PRODH4, 0PRODH5, 0PRODH6), we are using customized objects (ZPRODH, ZPRODH1, ZPRODH2, ZPRODH3, ZPRODH4, ZPRODH5, ZPRODH6).
    In transfer rules the mapped is as specified below
    Fields        =>  Info Objects.
    0ZPRODH1 => ZPRODH1
    0ZPRODH2 => ZPRODH2
    0ZPRODH3 => ZPRODH3
    0ZPRODH4 => ZPRODH4
    0ZPRODH5 => ZPRODH5
    0ZPRODH6 => ZPRODH6
    Now, when I schedule the Info Package, it is ending with an errors
    "Node characteristic 0PRODH1 is not entered as hierarchy charactersitic for ZPRODH"
    "Node characteristic 0PRODH2 is not entered as hierarchy charactersitic for ZPRODH"
    "Node characteristic 0PRODH3 is not entered as hierarchy charactersitic for ZPRODH"
    "Node characteristic 0PRODH4 is not entered as hierarchy charactersitic for ZPRODH"
    "Node characteristic 0PRODH5 is not entered as hierarchy charactersitic for ZPRODH"
    "Node characteristic 0PRODH6 is not entered as hierarchy charactersitic for ZPRODH".
    when i tried to load by flat file, there is no issues. But, flat file loading is not allowed for us.
    Please let me know any possible solution to handle this issue.
    Thanks.
    Regards,
    Patil.

    Hi voodi,
    Insted of using the info object 0PRODH1, we should use customized info object ZPRODH1 which I added already in the external characteristic in Hierarchy.
    Regards,
    Patil.

  • How to import Hierarchy Data in MDM 7.1

    Hi All,
        I am trying to import the hierarchy data to SAP MDM 7.1
    I have the data in the Excel sheet in the following structure
    Parent Code   Parent Name   Child Code   Child Name
    A1                  Printer              P1               Inkjet
    A1                  Printer              P2               Canon
    P1                   inkjet                Q1               Model - XXX
    P2                   Canon              Q2              Model - YYY
    In MDM i have 2 fields in the hierarchy table Code and Name as display fields.
    I tried to do partition of fields, combine fields as per the Import documentation. But i was not able to import the hierarchy.
    I have also seen some papers on SDN for Hierarchy import, but none of them talk about 2 display fields in the hierarchy table.
    Can anyone help me to import the data to MDM.
    Thanks,
    Priya.

    Hi Priya.
    You have three level hierarchy in your example
        A1    !     Printer
             P1   !    inkjet
                Q1   !    Model - XXX
    Parent Code ! Parent Name  ! Child Code ! Child Name
    in your import manager
    select "Partition Field/value" Tab
    In source partition window select  your "Parent code" filed
    press add
    select  your "Parent name" filed
    press add
    in window "Partition by:" select "Parent name" and "Parent code"  fields  and press "Combine" button
    for next fields you sould repeat previous steps
    then  select "Map Fields/values"
    find  in Field mapping Source field:  "Parent code [Partition]"
    map it to "Code"
    in "Values conversion mapping" window
    select all walues and press "Add" button then Add as Child
    More about import hierarchy:
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/b07849c7-3a5b-2b10-7586-c431d300a578
    Regards
    Kanstantsin

  • DELETE  HIERARCHY DATA,CONNECT BY  SQL/PLSQ

    Hi
    Please help with the logic!
    I am trying to delete the data from the hierarchy table data(TABLE1) based on another table(TABLE2),For this i am using 2 cursors (get_ssn and get_max),
    problem is with deleting the hierarchy data, there are several levels (few of them upto 10 levels), i have to delete from top to bottom level of the hierarchy structure
    the first cursor returns the hierarchy structure
    level ssn report_to baid
    1
    2
    3
    1
    2
    1
    2
    3
    4
    my plan is to pull the max of the level and delete it, loop the max value and decrement it by 1 in every iteration and delete the rows, below is the rough logic,
    please help me building up the logic
    declare
    lev eweb.level%TYPE;
    i = number :=0;
    cursor get_ssn is --> this cursor is getting ssn based on simple join between two tables
    select level, ssn, report_to, baid
    from TABLE1
    where ssn not in ( select e.ssn
    from TABLE1 e, TABLE2 s
    where e.ssn = s.ssn)
    start with ssn in (select e.ssn
    from TABLE1 e)
    connect by prior report_to=baid;
    cursor get_max is --> pulling the max of level
    select max(level)
    from eweb
    where ssn not in ( select e.ssn
    from TABLE1 e, TABLE2 s
    where e.ssn = s.ssn)
    start with ssn in (select e.ssn
    from TABLE1 e)
    connect by prior report_to=baid;
    BEGIN
    for i in get_ssn
    loop i := i+1;
    Delete from eweb --> here im trying to delete rows by using max(level)-i, in 1st iteration it takes the max value, in next iteration it will be max -1..........
    where level = get_max-i
    END LOOP;
    end for loop;
    END;
    Edited by: user8884944 on Jun 23, 2010 11:34 AM

    A few remarks
    1 The subject line was shouted by using all caps. This must be considered rude
    2 The introduction discusses 2 tables, yet the code deals with 3, and only from the third table data is deleted
    3 no CREATE TABLE statements were posted, nor sample data
    4 if you can put a constraint on the affected column, using on cascade delete, everything will be deleted automagically.
    With this little information, no help is possible. We can not see what each statement does, the comments don't tell anything, and we can also not see what it is expected to do in terms of logics, as the statements are almost certainly wrong.
    Sybrand Bakker
    Senior Oracle DBA

  • Hierarchy Data not saved after Hierarchy Load

    Hi Gurus,
    I am facing a problem with the hierarchy data load in SAP BPC NW 7.5 SP06. I have already used /CPMB/IMPORT_IOBJ_MASTER & /CPMB/IMPORT_IOBJ_HIER once to load the data from BI to BPC and it worked fine that time.
    Now I have made some changes in the Hierarchy at the BI side. When I run the package link list, the /CPMB/IMPORT_IOBJ_MASTER chain runs fine and the master data, description for Attribute and Hierarchies are loaded perfectly. But whn the /CPMB/IMPORT_IOBJ_HIER is run, the changes are not saved in the BPC Member sheet. I have manually make the changes in the member sheet and Process the Dimension.
    Can we process the Dimension explicitly after the Hierarchy load again?
    Does anyone have an idea about this?
    Any help is appreciated.
    Thanks,
    Abhishek

    Abhishek,
    Double check whether  /CPMB/IMPORT_IOBJ_MASTER is bringing all the ID's,Texts and Hierarchy Nodes. If required drop the data from dimesion member sheet and load it again.
    Double check the Hierarchy and level setup while running /CPMB/IMPORT_IOBJ_HIER.
    (when we are in SP05, it was not bringing the multiple Hierarchies, now we are in SP07 loading multiple hierarchies but not the TEXT fo the Id's some inconsistency)
    Thanks

  • How to upload the heirarchy data in BW system

    Hi All,
    I want to download & upload the hierachy data in BW. How can we do this, Please let me know.
    Thanks in advance.
    Regards,
    Vishal

    Hi Vishal,
    Pls use BW07 & BW10 Tcodes for generating the Hierarchy Data Source in R/3.
    If its a set of hierarchy you can use tcode BW07 to generate datasoucre, and for standard hierachies you must be having datasources already created.
    Now just replicate datasoucre in BW side, and in infopckage selection you can get newly created hierarchy. Select and schedule it, it will be loaded into BW.
    For External Hierarchy in BW , download to Flatfild and then upload.
    The useful link:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/0403a990-0201-0010-38b3-e1fc442848cb
    material hierarchy data source
    and:
    How to create a hierarchy datasource in R/3
    **PLS assign points,if info is useful***
    Regards
    CSM Reddy

  • Loading Hierarchy data from a DSO!

    Hi SDN,
    We have a ZTable containing a custom hierarchy in the SAP ECC system and we bring all its data into a staging DSO in BI via PSA.
    So now we have the hierarchy data in two places: PSA and a write-optimized staging DSO.
    Any idea how can we load the data from either of the two into a hierarchy? Is there a standard SAP BI function module which can be called by a program to input data and be loaded into the hierarchy tables?
    I know we have the option of dumping data into a flat file and then use a standard extractor to load. We prefer doing it the other way, if possible.
    Please advise.
    Thanks.
    SM

    Hello Shahid,
    I do ot think you can do this directly. you can use the method Arun mentioned to get what you want.
    Another way is that yuo can use flat file to load the hierarchy into Bi if you can export the Ztable to a file.
    Regards
    Jonas

  • How to upload Hierarchy data into BW InfoObjects

    I have gone through the XI and BI integration document provided by SAP and I found out that using that method only Master data and Text data can be uploaded into Infoobejects using Flexible upload which doesnt support Hierarchy data upload.
    I need to upload Hierarchy data into InfoObjects using SAP XI. Please suggest me the best way to upload the hierarchy data.
    Thanks and Regards,
    Shridhar.

    Hi,
    First , thanks for your answer.
    Concerning the scope of my project, currently we just have a SAP system to be integrated into BW but in a few times we will get also other OLAP Tools to integrate in BW. Also my customer want to manage all the message processing with only one product if it's possible and currently he use SAP XI for it so that's why he want's to use XI between SAP and BW.
    If i understand weel your answer, i can use XI without defining XML file in BW I can use standard extractor so XI just transfert IDOC  receving from SAP to BW , it that right ?
    Thansk again.
    Best regards.
    Bertrand.

  • Beginner question on creating hierarchy data

    We are moving data migration and other data bases to SAP and in the process of coming upto speed on SAP BI/BW using 7.0. I am working thru the Step by Step excercise by Fu et al.
    It has salesoff, salesregion and salesperson infoobjects. Salesperson infoobject has attribute of Salesperson name and we have edited external hierarchies to include salesoff and salesregion.
    Also, we manually entered master data for salesregion and salesoff - EAST, MIDWEST and WEST. To enter the hierarchy data for salesperson we were told that entering hierarchy data in 7.0 by a flat file is not enabled and will be only in 7.1 (is that correct?). So I tried doing it manually,
    a) I click on infobject Salesperson - create hierarchy.In that page I picked Create Characteristic node - entered salesoff - I get this message - salesoff is not a foreign characteristic.
    How do I get past this ? Should I not include salesoff and salesregion in the external char while creating salesperson.
    Is there something I missed in the StepbyStep ?
    Sanjay
    ps - when I learn to give out points I definitely will.

    Hi Sanjay,
    Have you enbled Hierarchy option for both Salesoff, Salesreg ?
    if enabled uncheck and activate infoobjects.
    SalesrepID should be hierarchy enable if you want to create Hierarchy using SalesrepID infoobject.
    on hierarchy, click on Maintain hierarchies to create Hierarchy, here give name of hierachy and discriptions on infoobject SalesrepID.
    and click on External chars. in hieracies to add Salesoff, Salesreg, and activate SalesrepID.
    Hope this helps
    Regards,
    Daya Sagar

  • Error while uploading data from a flat file to the hierarchy

    Hi guys,
    after i upload data from a flat file to the hierarchy, i get a error message "Please select a valid info object" am loading data using PSA, having activated all external chars still get the problem..some help on this please..
    regards
    Sri

    there is o relation of infoobject name in flat file and infoobjet name at BW side.
    please check with the object in the BW and their lengths and type of the object and check your flat file weather u have the same type there,
    now check the sequence of the objects in the transfer rules  and activate them.
    there u go.

  • How to delete entire data in the hierarchy table,?

    hi friends
    i need to delete entire data in the hierarchy table which contains parent child relationship,when i am selecting entire records and choose the option delete from the context menu, it is not deleting, and i have to delete one by one or i have delete first the child items and later parents items, it is time consuming process.
    Is there any other option to delete entire records in the hierachy table , irrespective of parent and child relationship?
    if any one have solution for my issue, please provide to me
    thanks in advance
    bharat.chinthapatla

    Hi Bharat,
      Unload the Repository and Delete the Table and fields in Hierarchy table and Recreate and reload the data.OIther wise you have to lot of manual work.
    Thanks
    Ganesh Kotti

Maybe you are looking for

  • Setting the number of consumers for a topic

    Hi, I have a topic connection factory from which I can creating 2 topic connections and setting different clientids for each connection to one topic.But I get a error com.sun.messaging.jms.ResourceAllocationException: [C4073]: A JMS destination limit

  • Existing software whic is on Actual mac book Pro transfereable on new one ?

    What about my existing software  which is on my actual mac book pro like FINAL CUT PRO and others,  and I want to buy a new mac book pro.  Do I  have to buy that software again ??  fernand

  • Is there an Indiana jones type font in the Adobe font generator program?

    I would like to use the Indiana Jones themed font in a video I'm making in After Effects CS6. None of the online fonts will allow me to color the words correctly. Is there an adobe program that can help and what's my best shot for importing into afte

  • Cannot access yahoo email, but can sign in and get to account or profile

    After I sign in and click read mail box it just keeps reading. I found an error message that says: Warning: Error in parsing value for 'background-image'. Declaration dropped. Source File: http://support.mozilla.com/en-US/home?as=u Line: 0

  • Need a swing scheduler

    Hi, I have a swing app that has diary feature. The user is able to add a note and time they went to see the alert. The diary entry gets stored in a mysql database. What’s the most efficient way to implement this? A thread which checks every minute if