Heirarchial queries

hi,
create table tree(child int, parent int)
How to find the grand parent of the child given
the child.
1,2
2,3
2,4
3,5
5,6
Now given 6 how can i find that its grand parent is 1.
thanks
Pramod
null

Try the following function:
CREATE OR REPLACE FUNCTION f_get_parent_id(PIN_CHILD NUMBER) RETURN NUMBER
IS
id NUMBER(10);
CURSOR c_id
IS
SELECT parent
FROM tree
CONNECT BY PRIOR parent = child
START WITH child = pin_child;
BEGIN
FOR c1rec in c_id
LOOP
id:= c1rec.parent;
END LOOP;
RETURN id;
END f_get_parent_id;
Test the above function from SQLPLUS:
SQL> select f_get_parent_id(6)
from dual;
F_GET_PARENT_ID(6)
1
null

Similar Messages

  • PO approval heirarchy - tables queries

    Hi,
    can anyone tell me how can i get the PO approval parties for any given PO from table queries?
    eg.
    PO num lvl1 lvl2 lvl3
    PO123 Jane Mary Peter
    assuming Jane is the first level of approval and Mary the next and Peter is the last.
    thanks.
    isabel

    do you meant the approval path?
    You will need to look at your approval hierarchy and also the employees table. are you using a direct or hierartchical approval chain?

  • A Single query with out the sub-queries

    I am using My-SQL as my back-end and it doesnot support the
    Sub-Queries. i have my table given below
    UserID..UserName..ParentUserID
    1........Admin...........0
    2........Sales...........1
    3........Sourcing........1
    4........SalesHead.......2
    5........SourcingHead....3
    6........SalesExec.......4
    7........SourExec........5
    The table contains heirarchy of users. The top most users
    has the ParentUserID as 0. and the remaining has their own ParentUserID
    I want to get the complete heirarchy of a given user in single ResultSet.
    It should be done without using sub-queries. but all joins can be used.
    e.g.
    if i say userid is 2 i should get following output:
    Sales - > SalesHead -> SalesExec->......
    Can any body please help me out!
    Sridhar.

    Hi Sridhar,
    You can use recursive method. Make a method as follows :
    public String getChildren(int UserID)
         String temp = "";
         Connection con = DriverManager.getConnection("","","");
         Statement st = con.createStatement();
         ResultSet rs = statement.executeQuery("select UserID from MyUsers where ParentUserID = " + UserID);
         while(rs.next())
              temp += " [ ";
              if(temp.equals(""))
                   temp += getChildren(rs(0));
              else
                   temp += " -> " + getChildren(rs(0));
              temp += " ] ";
         return temp;
    then call his method by providing any UserID to it and it will return you a string containing complete hierarchy in the following format :
    AAA -> BBB -> CCC -> DDD
    I hope it will help you.
    regards,
    Humayun

  • Please help me on following Queries on Web-IC)

    Hi CRM Experts,
    Please help me on following queries...
    1)How to enter data in ERP-Sales order in IC-Web Client?
    2)How to assign Sales areas in ERP-Sales order in IC-Web Client?
    3)How to Activate Incompletion Log and Header details in ERP-Sales oder in IC-Web Client?
    4)What is the differance between Heirarchial Categorization and Attribute Categorization in Multi Level categorization?
    Thanks in Advance.
    <b>Points will be rewarded.</b>
    Regards
    Sree

    Hi Sree,
    I've checked the doc Venkat adviced. But I think that the content might be too general for your questions. And at the same time, to distribute documents via email is not permitted in SDN forum. Please be noted.
    Let me try to provide some of my comments:
    1.For ERP Sales order, there are mainly two method
    - to use the standard navigation bar entry ERPSALESORDER
      which is in the standard SALES_B2B icwc profile;
    - to use ITS technical to call va01/va02/va03 transaction directly in browser
      for this you will have to define your own transaction launcher entry;
    2.Assign sales area
    - firstly, you need to define the sales area in ERP system as normal SD guys do;
    - then, in CRM system ppoma_crm, you will have to assign the ERP sales org/distribution channel/division to the CRM org unit, just as normal CRM sales guys do;
    (here is actually no special settings for ic webclient, only that for ic webclient, it is recommended to have unique sales area defined)
    3.Incompletion log
    - this follows the same settings as that iin ERP, SD guys do, this has no extra settings in CRM side
    4.Categorization
    - I believe this is a topic different with the ERP sales order topic, more like that in the service order, isn't it?
      I have to think about it before answerring.
    Hongyan

  • Heirarchy Tree in a Master Detail Relationship

    I am trying to use the heirarchy tree in a multiple tab
    interface form in Forms 6i. I have the tree populating properly
    on the initial master record query. However, I can't get the
    tree to clear on subsequent queries, like a master-detail clears
    on an ON-CLEAR-DETAIL trigger. The heirarchy tree doesn't
    clear, since no relationship is built between the master and the
    tree block. I'm using a procedure to do the populating. It gets
    called from several different triggers.
    Anyone done something like this before? How did you do it?
    Any assistance would be appreciated!
    Keith Geving
    [email protected]

    hmmm,
    If you're creating your tree from a record group you could Clear
    that group and build the tree again, this will create an empty
    tree:
    tree_recs := Get_Group_Row_Count(Group_id);
    for i in 1..tree_recs loop
    delete_group_row(Group_id, tree_recs - i + 1);
    end loop;
    ftree.set_tree_property('Your_Tree', ftree.record_group,
    Group_id);

  • List of queries where in a hierarchy being used.

    Hi -
    Could anyone please tell me how to find out list of queries where in a particular hierarchy is being used.
    Not the queries where a infoobject is used.
    I want the list of queries where a hierarchy is being used.
    Thanks for the help
    Praveen Tati

    Hi
    Go to the Hierarchies Table and say where Used list
    SE16
    CGPL_HIERARCHY
    COMC_HIERARCHY
    COMM_HIERARCHY
    COMM_HIERARCHYH
    COMM_HIERARCHYT
    COMM_HIERARCHYTH
    COMM_HIERARCHYWL
    HIERARCHY_ENTRY
    RSROLEHIERARCHY
    UPB_SY_HIERARCHY
    UPB_YT_HIERARCHY
    UPS_TP_HIERARCHY
    UPWB_HIERARCHY
    USS_BW_HIERARCHY
    BIC/H -- Heirarchy Table
    /BIC/K -- Heirarchy SID Table
    RXSELTXREF, RSCOMPDIR -- Reports/query relavent tables
    You can even go and see the Table RSRRREPDIR -- For the Directory of Reports
    Hope it helps

  • Could I have CASE or IF statement in FMS queries?

    Is it possible to have case statements in FMS queries:
    For example:
    SELECT T0.[U_DepoistfeeON] case
          when T0.[U_DepoistfeeON] is NOT BLANK  then $[$38.111.160]='Deposit Fee'
          when T0.[U_DepoistfeeON] is BLANK  then  then $[$38.111.160]=BLANK
    end FROM OITM T0
    What is wrong with above query please? Thank you very much.
    I do not mind even if above query is doable with an IF statement in it.

    Hi Rahul, this is what I want -
    I have a user defined field attached to item master OITM. The field is called : U_DepoistfeeON
    The above field contains additional depositFee taxes for selling beer bottles.
    I have also created a new tax as part of Freight handling. While on Sales Order screen, the Freight (unhide first through forms field) drop down can have the new tax type selected automatically "Deposit Fee".
    Thus, if the line item is of beer type that has U_DepositfeeON, then Freight field should automaticlally pick the type "Deposit Fee".
    If U_DepositfeeON is zero then I would like the Freight field on Sales Order screen ($38.111.160) set to blank.
    I tried to achieve this through following using case statement.
    select T0.U_DepoistfeeON
    from oitm t0
    case
    when T0.U_DepoistfeeON 0
    then $http://$38.111.160='Deposit Fee'
    when T0.U_DepoistfeeON = 0
    then $http://$38.111.160=''
    else
    $http://$38.111.160=''
    end;
    Of course it doesn't work. Note: I know I typed in DepoistfeeON, the error is not due to that.
    Thanks.

  • Manager Heirarchy is not getting displayed in P&L Dashboard

    Hi All,
    I have implemented the P&L Dashboard for Financials. Suddenly, It is not displaying the Manager Heirarchy in the Manager Parameter in the P&L Dashboard.
    Did anyone faced the same kind of problem, please throw some light.
    Regards,
    Chandana

    Hi,
    Thank you All.
    Regards,
    Shruti B.

  • How to Dene a Data Link Between Queries: Bind Variables

    This is an interesting topic and I cannot get it to work using Bind Variables.
    I have 2 queries: Q1 and Q2. Q2 needs c_id, account_code and account_type from Q1.
    Whe I run the data template below, I get only the data for Q1.
    Now people may argue that there is no data in Q2 for the relevant clause. So if I even remove the where clause in Q2 I still get no joy i.e Data appears for Q1 but not for Q2
    <dataTemplate name="FLCMR519_DATA_SET" description="Termination Quote Report">
         <parameters>
              <parameter name="cid" dataType="number" defaultValue="1"/>
              <parameter name="p_cln_id" dataType="number" defaultValue="62412"/>
         </parameters>
         <dataQuery>
              <sqlStatement name="Q1">
                   <![CDATA[SELECT qm.qmd_id,
    qm.contract_period,
    qm.quo_quo_id||'/'||qm.quote_no||'/'||qm.revision_no reference_no,
    qm.contract_distance,
    qm.mdl_mdl_id,
    q.qpr_qpr_id,
    q.quo_id,
    q.drv_drv_id,
    qm.revision_user username,
    pb.first_name||' '||pb.last_name op_name,
    pb.telephone_no,
    pb.facsimile_no,
    pb.email,
    q.c_id c_id,
    q.account_type account_type,
    q.account_code account_code,
    m.model_desc,
    ph.payment_description payment_head_desc,
    cl.fms_fms_id,
    cl.start_date,
    cl.end_date,
    cl.actual_end_date,
    cl.con_con_id,
    cl.cln_id,
    cl.term_qmd_id term_qmd_id,
    qm2.contract_period term_period,
    qm2.contract_distance term_distance
    FROM quotations q,
               quotation_models qm,
               contract_lines cl,
               personnel_base pb,
               models m,
               model_types mt,
               payment_headers ph,
               quotation_models qm2
    WHERE q.quo_id = qm.quo_quo_id
           AND cl.cln_id = :p_cln_id
           AND qm.qmd_id = cl.qmd_qmd_id
           AND qm2.revision_user = pb.employee_no (+)
           AND qm.mdl_mdl_id = m.mdl_id
           AND m.mtp_mtp_id = mt.mtp_id
           AND qm.payment_id = ph.payment_header_id
           AND qm2.qmd_id (+) = cl.term_qmd_id
    ]]>
              </sqlStatement>
              <sqlStatement name="Q2">
                   <![CDATA[SELECT ea.c_id,                  ea.account_type,ea.account_code,ea.account_name
    FROM external_accounts ea
                 WHERE ea.c_id = :c_id
                   AND ea.account_type = :account_type
                   AND ea.account_code = :account_code
    ]]>
              </sqlStatement>
         </dataQuery>
    </dataTemplate>

    Defining dataStructure section is mandatory for multiple queries.

  • How to use one WAD template for all the available queries

    Hi,
    I have created a WAD template... Now we have close to 25 queries which will use that template for displaying their output at Portal...
    Is there any way that i don`t have to create multiple copies of my WAD template...
    I.e. all queries would call that same template through portal...

    Hi,
    The Bex report uses the Standard Template 0ANALYSIS_PATTERN while it is executed.
    So if your sure that the look and feel of all the Reports is going to remain same, you don't need to even attach all these Queries to Templates in WAD.
    When you execute the BEx query, it would pick up the standard template and run it in portal.
    But if you want to customize the Report Template:
    1) You can change this standard template 0ANALYSIS_PATTERN  and customize it according to ur requrement in WAD.
    2) Or you can create a copy of this standard template and change it as required. Then change the template in spro (transaction RSCUSTV27) to point to this Z template.
    Let me know if you need more details.
    Regards,
    Forum

  • How to Display Heirarchy and Character at a time in the report...

    Hi
    I have a req ...where I need to design a query to display a character and its heirarchy colum by colum...I mean, I have document type master data info object it has texts and Heirarchy data source...and we loaded this data...Also we have document type directly coming from ECC  Transactional DS...Now When I take this document type and do not select heirarchy its displaying the document types (KN,KA ,KR etc...)..If I select the heirachy in my query..its displaying in heirarchy structure and the document types (KN,KA,KR ) are displaying as the last nodes. But I want to display the heirarchy and also the document type in 2 diff colums... how it would be possible..is there any thing needs to be done at query level / do i need to take a RKF / CKF and write any code to bring heir and info object value?
    Iam bit confused here..pelase advice ASAP.
    regards

    you cannot have the same character in the query twice.  You can either have it in the hier format or just the char.
    I am wondering why you need to display the same characters twice in each column.
    The best way is to have them in the hier. format and in the char. properties expand the node level as you want so you will see them in the detail level.
    assign points if helpful

  • Error while Activating / running Bex queries/reports

    Hello
    I have following ERRORs while activating / running BEx reports/queries.
    1. While Activating BEx reports, I keel getting following ERRORS
    Object directory entry R3TR ELEM E341OIR6G715GUMGN0MRXP3MA does not exist
    Error when activating element BX7FOOKQB4588RROCBTC2YVZN
    BEx transport request 'BIDK901352' is not available or not suitable
    2. While running the BEx report/query in Bex Analyzer, I'm getting ERROR in entering the parameters, its NOT allowing / giving me option to select the parameters, for example for 0COSTCENTER, it is NOT displaying list costcenters to select before I can RUN that particular report.
    3. How can I trouble shoot ERRORs related to BEx and Portal connectivity.
    4. How would I setup the Variants for a Bex query/report ? Are these Variants for per user basis / per report basis. Can I have each variant for particular users OR all users must select their own variant each time when they RUN the report ? 
    Thanks, Sorry I have asked multiple questions, in jst one thread.
    BI

    Goto SE03 -->Search for Objects in Requests/Tasks  option , select the object type and execute it will give all the transports it has collected before ..
    Also you can use transport connection in RSA1 and select the query and find out all the objects in query locked by what request etc ..
    Thanks,
    Ravi

  • Error while transporting Queries

    Hi,
    I am getting this error while transporting queries!!
    Object '!ZTIC_UKA' (ELEM) of type 'Query' is not available in version 'A'
    Message no. RSO252
    Diagnosis
    You wanted to generate an object with the name '!ZTIC_UKA' (in transport request ELEM) of type 'Query' (TLOGO). This is, however, not available in the BW Repository database. It does not exist in the requested version A. If the version is 'D' then it is possible that an error arose during the delivery or installation. If the version is 'A' then the Object was either not created or not activated.
    System Response
    The object was not taken into account in the next stage of processing
    Thanks

    Hi Murali,
    YOu are trying to transport the element ZTIC_UKA'  of the query,may be an variable  which is not colelcted in the request.
    Try to transport the query through RSA1> Transport connection->Query-->give you query name -->Drag and Drop to Right hand side  and Click on collect all dependent objects and check whetehr they have collected in the same request.Make sure ur variables are collected.
    Tranport it now and Check.
    Rgds
    SVU123
    Edited by: svu123 on Mar 4, 2010 7:41 AM

  • Need procedure for creation of BW Roles, Assigning Queries,Publishing Roles

    Hi Experts,
      Could you please let me know the procedure for creation of BW Roles, Assigning Queries,Publishing Roles in Business Explorer (BEx - BW 3.5)
    Thanks in advance,
    Andy

    Hi,
    Creating BW Roles
    http://help.sap.com/saphelp_nw04/helpdata/en/52/6714b6439b11d1896f0000e8322d00/frameset.htm
    Assigning Queries
    After creating the query, save the query to a role from the query designer.
    Publishing Roles in Business Explorer
    https://websmp101.sap-ag.de/~sapdownload/011000358700002894802003E/HowToBIPortal1.pdf
    Hope this helps you..!
    -Pradnya

  • Problem using DECODE() function with a Query of Queries

    I
    posted
    on my blog about an issue I was having trying to use the PL/SQL
    DECODE() function with a Coldfusion Query of Queries. This function
    works fine when you query a database for information. However, when
    you query another query, it seems that CF doesn't recognize it. I
    got errors stating that it found a left parenthesis where it
    expected a FROM key word. Here is a simplified version of what I am
    trying to do:
    quote:
    <!--- Simulated query; similar to what I was calling from
    my database --->
    <cfscript>
    qOriginal = queryNew("Name,Email,CountryCode",
    "VarChar,VarChar,VarChar");
    newRow = queryAddRow(qOriginal, 5);
    querySetCell(qOriginal, "Name", "Joe", 1);
    querySetCell(qOriginal, "Email", "[email protected]", 1);
    querySetCell(qOriginal, "CountryCode", "AMER", 1);
    querySetCell(qOriginal, "Name", "Sally", 2);
    querySetCell(qOriginal, "Email", "[email protected]", 2);
    querySetCell(qOriginal, "CountryCode", "AMER", 2);
    querySetCell(qOriginal, "Name", "Bob", 3);
    querySetCell(qOriginal, "Email", "[email protected]", 3);
    querySetCell(qOriginal, "CountryCode", "ASIA", 3);
    querySetCell(qOriginal, "Name", "Mary", 4);
    querySetCell(qOriginal, "Email", "[email protected]", 4);
    querySetCell(qOriginal, "CountryCode", "EURO", 4);
    querySetCell(qOriginal, "Name", "John", 5);
    querySetCell(qOriginal, "Email", "[email protected]", 5);
    querySetCell(qOriginal, "CountryCode", "EURO", 5);
    </cfscript>
    <cfquery name="qCountries" dbtype="query">
    SELECT DISTINCT(CountryCode) AS CountryCode,
    DECODE(states, "AMER", "North America &amp; Canada",
    "EURO", "Europe &amp; Africa", "ASIA", "Japan &amp;
    Asia","") CountryName
    FROM qOriginal
    ORDER BY CountryCode
    </cfquery>
    <cfdump var="#qCountries#">
    <!--- ========== END OF CODE ========== --->
    So running this returned the following error:
    Query Of Queries syntax error.
    Encountered "(. Incorrect Select Statement, Expecting a
    'FROM', but encountered '(' instead, A select statement should have
    a 'FROM' construct.
    Does anybody know why this doesn't work? Is it just not
    supported? Please note that I have also tried to use the CASE()
    function instead of DECODE() and that resulted in basically the
    same error. For now I an looping over my distinct query with a
    switch statement and manually loading a new query with the data how
    I want it. But it would be a lot cleaner and less code to have the
    DECODE() to work. Thx!

    DECODE() is an Oracle function, not generic SQL. Q-of-Q is a
    very limited subset of SQL and lacks many functions and clauses
    available in standard SQL, especially what you may be used to using
    in your particular RDBMS.
    See
    Query
    of Queries user guide
    Phil

Maybe you are looking for

  • Fields not getting displayed in Sapscript

    Hi Guyz, I have a customized Sapscript form ZPV_INVOICE and its print program RVADIN01. This form outputs the Sales Invoice. When the print preview is triggered, Material number (MATNR) is not getting displayed on the form. However, when the form is

  • Can I send money from my iTunes account to buy apps?

    i just got my new ipod touch 5<3 i love it its awesome in everyway, but i got a gift card for itunes and not for the app store so i was wondering if there was a way to send/transfer/or share money between the two accounts since their under the same a

  • Installation /Download of xMII 11.5 from SMP

    Dear all, We want to install xMII 11.5 (as 12.0 will be available after Sept.2007). We want to install demo version with apprppriate license obligations . May I request to help on following ? 1. On SMP SAP site, where I can look for xMII 11.5 downloa

  • DB level to lock and unlock

    i need to create a function is_user_blocked(p_user varchar2). this functions should handle the lock and unlock users on DB level. Returns 0 if the user is not blocked, returns 1 if the user is blocked, please help me in this regards mkhaleel

  • How do i get out of "no bootable device"

    I just tried to do boot camp on my laptop with windows vista, but i canceled the installation and got the cd out. now  i turn on the computer and it says no bootable device" i dont want to install windows on my laptop anymore. what do i do