Query to find parent & al children customer based on child Party_number

Hi All,
I am working analyzing some TCA hierarchy data for a new customer dimension table design for a project and also for better understanding of the TCA.
I need a query which can help me in listing all the PARTY IDs of all the customers that come under the top most rolled up customer which is found based on an any random input CHILD PARTY NUMBER.
In simple terms.
1. I have any random PARTY NUMBER of any customer in HZ PARTY.
2. Using that PARTY NUMBER I need to find it's top most level rolled up parent customer.(i.e. Which global parent customer it falls under)
3. Now based on the global customer found in the second step, I need to find all the customers (and all its global subsidiaries) under that one global name.(All the customers which are spread across the glob)
I am currently using the following tables to build the logic.
hz_parties
hz_relationships
hz_hierarchy_nodes
fnd_lookup_values
Anybody who has done such an exercise or has any kind of inputs, queries which can help, etc.. it would be really helpful.
Thanks a lot.
Thank you,
Warm Regards
Goldi

hi goldie,
u can use
party_id (pk) from hz_parties,
party_id(fk) and cust_account_id(pk) from hz_cust_accounts,
cust_account_id(fk) from AR.HZ_CUST_ACCT_RELATE_ALL.
i hope u can get the way for your answer..
pls let me know, it worked or not.
Regards.
Pushpal

Similar Messages

  • Recursive query for finding parents and children against two tables

    Hi I have two tables where the data is stored hierarchially.
    I have found using connect_by, level and other oracle functions doing its job when the data is in one table.
    Can I traverse against two tables by using the same oracle functions.
    My Table A can go 2 levels deep in my hierarchy and level 3 and so forth has to be done against a different table.
    Appreciate your insight..
    Thanks in advance

    The number of levels that I can traverse in the first table is dynamic (sometimes 2 levels and sometimes 3 levels and actually no level limit) and then has to dynamically start looking at second table for finding any more levels in the other table.
    I was able to implement them seperately and union them.
    I was more looking for a comprehensive solution to reduce the number of lines that I have to maintain...
    Thanks in advance
    Edited by: user566193 on Jan 15, 2010 1:58 PM

  • Stuck on sql query to find parent records that have the same child records

    Oracle 10gR2 Enterprise Edition.
    Hi,
    I'm trying to write some logic to look for records in a parent table, which have the exact same values in a child table.
    This is part of a bigger query, but I'm stuck on this part for now, so I've mocked up some simplified tables below to capture the core of the
    problem I'm stuck on.
    Let say I've got a parent table Manager, a child table Employee and there's a many to many relationship between them.
    The aptly named Join_Table handles the relationship between them. So one manager can manage many employees, one employee can be managed by
    many managers.
    I've a feeling this is stupidly easy, but I seem to be suffering from a bad bout of brain freeze today!
    -- parent table
    CREATE TABLE manager (
    id      number primary key,
    name      varchar2(100));
    -- child table
    CREATE TABLE employee (
    id          number primary key,
    name      varchar2(100));
    -- link table
    CREATE TABLE join_table (
    manager_id          NUMBER,
    employee_id      NUMBER,
    CONSTRAINT join_table_pk PRIMARY KEY (manager_id, employee_id),
    CONSTRAINT manager_fk FOREIGN KEY (manager_id) REFERENCES manager(id),
    CONSTRAINT employee_fk FOREIGN KEY (employee_id) REFERENCES employee(id)
    -- Insert some managers
    INSERT INTO manager (id, name) VALUES (1, 'John');
    INSERT INTO manager (id, name) VALUES (2, 'Bob');
    INSERT INTO manager (id, name) VALUES (3, 'Mary');
    INSERT INTO manager (id, name) VALUES (4, 'Sue');
    INSERT INTO manager (id, name) VALUES (5, 'Alan');
    INSERT INTO manager (id, name) VALUES (6, 'Mike');
    -- Insert some employees
    INSERT INTO employee (id, name) VALUES (101, 'Paul');
    INSERT INTO employee (id, name) VALUES (102, 'Simon');
    INSERT INTO employee (id, name) VALUES (103, 'Ken');
    INSERT INTO employee (id, name) VALUES (104, 'Kevin');
    INSERT INTO employee (id, name) VALUES (105, 'Jack');
    INSERT INTO employee (id, name) VALUES (106, 'Jennifer');
    INSERT INTO employee (id, name) VALUES (107, 'Tim');
    -- Insert the links
    -- John manages Paul, Simon, Ken
    INSERT INTO join_table (manager_id, employee_id) VALUES (1, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (1, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (1, 103);
    -- Bob manages Paul, Simon, Kevin, Jack
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 104);
    INSERT INTO join_table (manager_id, employee_id) VALUES (2, 105);
    -- Mary manages Jennifer, Tim
    INSERT INTO join_table (manager_id, employee_id) VALUES (3, 106);
    INSERT INTO join_table (manager_id, employee_id) VALUES (3, 107);
    -- Sue manages Jennifer, Tim
    INSERT INTO join_table (manager_id, employee_id) VALUES (4, 106);
    INSERT INTO join_table (manager_id, employee_id) VALUES (4, 107);
    -- Alan manages Paul, Simon, Ken, Jennifer, Tim
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 103);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 106);
    INSERT INTO join_table (manager_id, employee_id) VALUES (5, 107);
    -- Mike manages Paul, Simon, Ken
    INSERT INTO join_table (manager_id, employee_id) VALUES (6, 101);
    INSERT INTO join_table (manager_id, employee_id) VALUES (6, 102);
    INSERT INTO join_table (manager_id, employee_id) VALUES (6, 103);
    -- For sanity
    CREATE UNIQUE INDEX employee_name_uidx ON employee(name);So if I'm querying for manager John, I want to find the other managers who manage the exact same list of employees.
    Answer should be Mike.
    If I'm querying for manager Mary, answer should be Sue.
    This query will give me the list of managers who manage some of the same employees as John, but not the exact same employees...
    SELECT DISTINCT m.name AS manager
    FROM manager m, join_table jt, employee e
    WHERE m.id = jt.manager_id
    AND jt.employee_id = e.id
    AND e.id IN (
         SELECT e.id
         FROM manager m, join_table jt, employee e
         WHERE m.id = jt.manager_id
         AND jt.employee_id = e.id
         AND m.name = 'John')
    ORDER BY 1;I thought about using set operations to find managers whose list of employees minus my employees is null and where my employees minus their list of employees is null. But surely there's a simpler more elegant way.
    Any ideas?
    Btw, I need to run this as a batch job against tables with >20 million rows so query efficiency is key.

    What about...
    WITH manager_list AS
    SELECT name,
            LTRIM(MAX(SYS_CONNECT_BY_PATH(id,','))
            KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
    FROM   (SELECT m.name,
                    e.id,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev
             FROM   manager m,
                    join_table jt,
                    employee e
      WHERE m.id           = jt.manager_id
      AND   jt.employee_id = e.id
      AND   m.name = :P_MANAGER)
      GROUP BY name
      CONNECT BY prev = PRIOR curr AND name = PRIOR name
      START WITH curr = 1
    ), all_list AS
    SELECT name,
            LTRIM(MAX(SYS_CONNECT_BY_PATH(id,','))
            KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
    FROM   (SELECT m.name,
                    e.id,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) AS curr,
                    ROW_NUMBER() OVER (PARTITION BY m.name ORDER BY e.id) -1 AS prev
             FROM   manager m,
                    join_table jt,
                    employee e
      WHERE m.id           = jt.manager_id
      AND   jt.employee_id = e.id)
      GROUP BY name
      CONNECT BY prev = PRIOR curr AND name = PRIOR name
      START WITH curr = 1
    SELECT a.*
    FROM   manager_list m,
           all_list a
    WHERE  m.employees = a.employeesWould be easier in 11g, but I don't have an installation here so this is based on 10g.
    Cheers
    Ben

  • Xpath Query to find parent nodes

    My XMl is like this
    <UserAgent1>
    <Name>QTS </Name>
    <NetworkFamily>GSM</NetworkFamily>
    <NetworkSupportedMap>0x06</NetworkSupportedMap>
    </UserAgent1>
    <UserAgent2>
    <Name>QuickTime</Name>
    <NetworkFamily>GSM</NetworkFamily>
    <NetworkSupportedMap>0x06</NetworkSupportedMap>
    </UserAgent2>
    Now if they give a search String like "GSM" without specifying any tag
    Then i use the xpath query
    //*[contains(text(),'GSM')]
    This will give me the child element <NetworkFamily>GSM</NetworkFamily> . .and with this i will find out the parent element which is <UserAgent1> & <UserAgent2>
    IS there any query which will give me directly the Parent Nodes whose childnodes contain the given text ?

    Well, of course there is. But I couldn't remember how so I googled the keywords "xpath parent". The first link that came back suggested
    //*[contains(text(),'GSM')]/..
    and the second suggested the parent axis
    parent::(//*[contains(text(),'GSM')]) or maybe //parent::*[contains(text(),'GSM')]
    So yes, there's several ways. And they were easy to find with Google too.

  • Query to find 18 yrs Children

    Hi All,
    Can anybody tell me, how to write a Query to find the persons date of birth less than or equal to 18 yrs till today ?
    Thanks in advance.

    Something else like this ?
    SQL> select * from mytable;
    USERNAME                       CREATED
    SYS                            13/11/05
    SYSTEM                         12/11/05
    OUTLN                          11/11/05
    DBSNMP                         10/11/05
    PS                             09/11/05
    H89UCBAC                       08/11/05
    PEOPLE                         07/11/05
    TOTO                           09/11/06
    8 rows selected.
    --Take the users created in the last year.
    SQL> select *
      2  from   mytable
      3  where created>=add_months(sysdate,1*-12)
      4  /
    USERNAME                       CREATED
    TOTO                           09/11/06
    SQL> Nicolas.

  • Function module to find the Credit limit of a Customer based on Credit Area

    hi Experts,
                       Is there any function module to find the Credit limit of a Customer based on Credit Area.
    Regards,
    Dheepak

    hi
    try this:
      select single * from KNKK INTO zzKNKK
          where KUNNR = xkunnr and KKBER = xkkber.
    credit limit: zzKNKK-KLIMK...
    regards,darek

  • How to find Tables behind a Custom Query in SAP

    Hi Gurus,
    Can anyone please help me find tables behind a custom query in SAP.
    Regards
    As

    Hi
    Check the name of the programm assigned to transaction, it should be like this:
    AQZZ<user group>=======<query name>======
    or
    AQIC<user group>=======<query name>======
    It depends of the query area is global or cross-client
    So run SQ01, select the quey area, select the quey group and so your query: now you can see the infoset and then you see it by SQ02 transaction
    Max

  • Sql query to find the balances for a customer account wise.

    Hi,
    Could someone help me with the sql query to find the balances for each customer account wise. This is need to generate the report.
    presently we are using this query, but the output doesnot return the expected result.
    SELECT sum(nvl(ps.acctd_amount_due_remaining,0)) "Balance"
    FROM      ra_cust_trx_line_gl_dist_all gld,
              gl_code_combinations c,
              ar_payment_schedules_all ps,
              RA_CUSTOMER_TRX_ALL rat,
              ra_customers rc
    WHERE      c.CHART_OF_ACCOUNTS_ID = 101
    and gld.code_combination_id = c.code_combination_id
         and rat.CUSTOMER_TRX_ID=gld.CUSTOMER_TRX_ID
         and rat.CUSTOMER_TRX_ID=ps.CUSTOMER_TRX_ID
    and ps.customer_id=rc.customer_id
         and ps.status='OP'
         and ps.gl_date <= :PDATE
         and ps.org_id=:PORGID
         and ps.class in ('GUAR','INV','DM','DEP')
    and c.SEGMENT4=:Account_id
    and ps.customer_id=:Customer_id
    Thanks in advance.
    Kalyan.

    Can someone help us with this.

  • Query to find the parent group name

    what is/are the table name that i should use to find the parent name of the job?
    thank you,
    warren

    Hi Warren,
    The parent group name (dbo.jobmst.jobmst_prntname) can be found within jobmst table.
    For example, the below query will return parent name of a specified job:
    SELECT dbo.jobmst.jobmst_prntname
    FROM dbo.jobmst
    WHERE dbo.jobmst.jobmst_name = 'Enter name of job here'
    BR,
    Derrick Au

  • SQL query to find all the custom folders in Discoverer (query posted)

    I know its not a question I am posting..this is just to inform community users that this query makes life easier in case someone wants to find out all the custom folders in a particular EUL (folder name starting with XX)
    select b.ba_name,f.obj_name folder_name,f.obj_id,f.obj_ext_owner Owner
    from
    APPS.EUL5_objs f
    , APPS.EUL5_ba_obj_links l
    , APPS.EUL5_bas b
    where 1=1
    and f.obj_id= l.bol_obj_id
    and b.ba_id= l.bol_ba_id
    and b.ba_name like 'XX%'
    order by b.ba_name,f.obj_name;
    Hopefully it would be useful to others!

    Connect as sysdba and try..
    To list all objects >100M in size.
    SQL> select owner, segment_type, segment_name, sum(bytes)/(1024*1021) from dba_segments
    group by owner, segment_type, segment_name
    having sum(bytes)/(1024*1021) > 100
    For tablespaces ..
    select tablespace_name, sum(bytes) tablespace_size
    from dba_data_files
    group by tablespace_name
    union all
    select tablespace_name, sum(bytes) tablespace_size
    from dba_temp_files
    group by tablespace_name
    order by tablespace_name

  • Query to find sales group details based on a merchant.

    I wanted a query to find the sales group details for a given merchant. How do i do it?

    Hi,
    use for following function module to get file listing
    DATA: L_DIRNAME LIKE EPSF-EPSDIRNAM,
          L_FILEMASK LIKE EPSF-EPSFILNAM.
    CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
        EXPORTING
          dir_name                  = l_dirname
          file_mask                 = l_filemask
    * IMPORTING
    *   DIR_NAME                    =
    *   FILE_COUNTER                =
    *   ERROR_COUNTER               =
        TABLES
          dir_list                  = pi_filelist
    EXCEPTIONS
       invalid_eps_subdir           = 1
       sapgparam_failed             = 2
       build_directory_failed       = 3
       no_authorization             = 4
       read_directory_failed        = 5
       too_many_read_errors         = 6
       empty_directory_list         = 7
       OTHERS                       = 8.

  • Need a query to find Grops mapped on Folders

    Hi ,
    I need a query builder query to find out the list  of folder and mapped groups to those folder.
    Would you please let me know if that is possible I triead but no luck .
    Regards,
    Neo

    Hi,
    This query sound goods but I get error 
    Select SI_NAME, SI_KIND From CI_APPOBJECTS, CI_INFOOBJECTS
    Where PARENTS("SI_NAME='Myfolder'",'CHILDREN(''SI_NAME=''UserGroup''')")
    Please let me know if I am giong in right direction becuse I never used Parents and child concept bit confused.
    All I need is when I put in my folder name it has to show me all the groups mapped to it.
    If this query gives  the result , it will be the great logic I would say
    Thanks a ot.
    Neo A

  • Find parent/child relationships At More Than 2 Levels

    Hello,
    Does anyone have a solution to find parent/child relationship for data more than 2 levels deep?
    I have a solution when there's a simple parent-child relationship but not when there's a grandparent-parent-child relationship or deeper.
    Ex. I have a table company_parent_child that stores the relationship betwen a company and it's direct parent.
    create table TEMP_COMPANY_PARENT_CHILD
    PARENT_ID NUMBER(10),
    COMPANY_ID NUMBER(10)
    insert into TEMP_COMPANY_PARENT_CHILD values (1, 10);
    insert into TEMP_COMPANY_PARENT_CHILD values (1, 11);
    insert into TEMP_COMPANY_PARENT_CHILD values (1, 12);
    insert into TEMP_COMPANY_PARENT_CHILD values (2, 13);
    insert into TEMP_COMPANY_PARENT_CHILD values (10, 100);
    insert into TEMP_COMPANY_PARENT_CHILD values (10, 101);
    insert into TEMP_COMPANY_PARENT_CHILD values (10, 102);
    insert into TEMP_COMPANY_PARENT_CHILD values (11, 103);
    1->
    ___10->
    ______100,101,102,
    ___11->103
    Companies 100, 101 and 102 are under parent 10 and grandparent 1.
    I need to create such a view or another temp table so that when I pass the parent ID, I will pull all the children on all levels. In addition, and this is the tricky part, when I join this new temp table or view to another data table without any parameters, the data should not be duplicate, ie. each company ID should appear only once.
    create table TEMP_JOIN
    company_id number(10),
    order_id varchar2(10)
    insert into TEMP_JOIN values (100, 'a');
    insert into TEMP_JOIN values (101, 'b');
    insert into TEMP_JOIN values (102, 'c');
    insert into TEMP_JOIN values (103, 'd');
    insert into TEMP_JOIN values (10, 'e');
    insert into TEMP_JOIN values (11, 'f');
    insert into TEMP_JOIN values (12, 'e');
    insert into TEMP_JOIN values (13, 'f');
    Thanks.

    start by learning CONNECT BY/START WITH. once you've
    written a query to read the grandparent-parent-child
    relationship, then come back with more questionsYes. we did look heavily into connect by/start with, in fact along with "connect_by_iscycle","connect_by_isleaf","connect_by_root" as well.
    Our dilemma is that when a joint is made between those two tables mentioned above TEMP_COMPANY_PARENT_CHILD and TEMP_JOIN, we are not able to create a view that would contain distinct company_ids, each mapped to a unique order id.
    The problem is we cannot have this type of joint when there are "n" level relationship between companies (or company_id). Basically, I think we should have our unique order id mapped to a unique key. This unique key should be a specialized key that we can know at anytime the entire path of the ancestry which we can know by sys_connect_by_path(company_id,'/') path.
    How do we know which path to take. The best bet is to "connect_by_isleaf" and just have the distinct "deep" path which form the specialized unique key. If you need help on this let me know. (A hint, sort by LEVEL and then do a rank after partitioning by company id and then filter the records by rank = 1, try this one!!!)
    So, we will eventually have a joint (say Table X) like
    PATH ORDER_ID
    /1/10/100 a
    /1/10/101 b
    /1/10/102 c
    /1/10 e
    /1
    /1/11/103 d
    /1/11 f
    I think this is the best view we can have to maintain a joint with no repetition along PATH as well as ORDER_ID. If you have any other thoughts, let me know.
    Then you query by path using INSTR to pull records by company_id.
    for example, if you want to get all the children for company_id "10" you would just say
    select * from X where INSTR(PATH,10,1,1) <> 0
    or if you want to get all the children for company_id "11" you would just say
    select * from X where INSTR(PATH,11,1,1) <> 0
    What do you think? Has anyone used the path information for traversing the tree? Or is there any article that tells us how to make effective use of sys_connect_by_path(company_id,'/') path.
    Thank you. Hope it made sense!

  • Correlated query to find cheapest manufacturer for a product

    Hi,
    I have a SQL Query that returns me:
    - the "product code" i must purchase,
    - the "quantity" to purchase for this product
    - and if it's in "promotion or not".
    Based on this result, i must to look at "manufacturer" table and find the cheapest "price" for each product to purchase and the quantity available at the manufacturer.
    If "quantity to order" (e.g. 20) is higher than "quantity available" (e.g. 12) at "cheapest manufacturer", i must order the missing quantity (8) to the next cheapest manufacturer.
    How can i do that ?
    thx

    ​Hi
    >>correlated query to find cheapest manufacturer for a product
    I have created two table [ProdTable] , [Product Code] to get the cheapeast manufacturer  for a product  which you can refer to .
    [Product Table]
    [Prod Table]
    select [ProdTable].[S_Prod_Code],Min([ProdTable].[Prod_Cost]) as MiniCost
    from [ProdTable] inner join [Product Table] on [ProdTable].[S_Prod_Code]=[Product Table].[Product Code]
    Where [Product Table].[Promotion]<>"YES"
    group by [ProdTable].[S_Prod_Code]
    Using the above query ,you can get the cheapest  cheapeast manufacturer  for a product , which the promotion is not YES
    >>for promotional products, i must firstly check if the cheapest manufacturer has enough prod in stock. If not, i order all the prod in stock the manufacturer has, and i must order to missing ones to the next cheapest manufacturer
    Are you looking for a select query or an update to the table or form design ?Can you separate your business rules with the technolege ?  So more people could understand your issues well to give you more help.
    Thanks for your understanding
    Best Regards
    Lan
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • BO SDK Query to find all folders that a user has access to

    Hi Experts
    Please help me on BO SDK Query to "find all folders that a user has access in a single query".
    I am tried trial & error using PARENTS & CHILDREN. nothing worked
    Please advice
    Thanks!
    Prasath

    Hi Aasavari
    I am checking BO Web services samples and .NET samples. Please advice me the correct files to check the user/folder rights.
    Thank you so much
    Prasath
    http://wiki.sdn.sap.com/wiki/display/BOBJ/NETWebServicesSDKSamples

Maybe you are looking for

  • Save as 8 or 16-bit from RAW?

    Can anyone recommend me saving my RAW files into 16-bit tiff before reproduction? I shall soon have a number of RAW CR2 Canon-sourced files that I want to process into tiffs and ultimately convert to black and white for repro in a book with a modest

  • Unintended Links Encrypted in PDF?

    Hi Adobeians, I am experiencing an issue with Indesign/Acrobat where almost all of my PDF exports have this encrypted link that I cannot get rid of. I have tried re-typing the text, and in most cases it works and in other cases it does not. I have ch

  • Account Segmentation - Setup

    Hi All! Can somebody tell me how to remove a segment ID specifically "extra" in this setup? And also I can't edit the Size and Type. (Administration>Setup>Financials-->Account Segmentation) Please check this link for screen shot. [http://img43.images

  • ORA-13754: "SQL Tuning Set" "" does not exist for user "SYS"

    While calling dbms_stats.seed_col_usage I got the following error. Can someone help me on how to resolve it sqlplus SQL*Plus: Release 11.2.0.1.0 Production on Thu Apr 14 14:37:38 2011 Copyright (c) 1982, 2009, Oracle. All rights reserved. Enter user-

  • Lion will not play any type of video AT ALL

    Problem after problem. No login to itunes...10 hours of troubleshooting later itunes is fixed. Now it will not play any type of video.....nothing. I'm starting to feel I have made a big mustake going to apple. An Ultra expensive version of windows th