Parent Child Query Solution Required

Hi All,
I am developing an accounting application...I have two tables...CHARTS & DETAILS. FOLLOWING IS THE STURCTURE ALONGWITH SAMPLE DATA.
CHARTS
ACC_CODE NUMBER(8)
ACC_NAME VARCHAR2(50)
PARENTAC NUMBER(8)
SAMPLE DATA:
ACC_CODE ....ACC_NAME....................PARENTAC...................................
100000............CASH AT BANKS...............NULL .........................................
100001............BANK OF AMERICA...........100000........................................
100002............BANK OF ARKANSAS........100000........................................
100003............BANK OF CALIFORNIA.......100000........................................
DETAILS
ACC_CODE NUMBER(8)
VDATE DATE
DEBIT NUMBER(13,2)
CREDIT NUMBER(13,2)
ACC_CODE ....VDATE....................DEBIT......................CREDIT....................
100001............ 01-01-07.....................5,000...................................................
100001............ 02-01-07.....................6,000...................................................
100001............ 03-01-07.....................9,000...................................................
100001............ 04-01-07.....................75,000.................................................
100002............ 02-01-07......................................................6,500..................
100002............ 03-01-07.....................................................12,870..................
100002............ 04-01-07.......................................................5,000..................
100002............ 05-01-07.......................................................9,850..................
Now my user wants to enter the parent account code e.g 100000 means he/she wants to see the sum of debit and credits of all the accounts in details whos parent is 100000 ( CASH AT BANKS)...
DESIRED RESULT IS :
Account Code...................Sum OF Debit.............Sum of Credit.......................
100001..................................95,000...........................0..................................
100002......................................0............................34,220.............................
can you please tell me what will be sql to pick data from both tables with sum.
thanks

To prove Laurent's SQL is working:
SQL> create table charts
  2  as
  3  select 100000 acc_code, 'CASH AT BANKS' acc_name, cast(null as number(6)) parentac from dual union all
  4  select 100001, 'BANK OF AMERICA', 100000 from dual union all
  5  select 100002, 'BANK OF ARKANSAS', 100000 from dual union all
  6  select 100003, 'BANK OF CALIFORNIA', 100000 from dual
  7  /
Tabel is aangemaakt.
SQL> create table details
  2  as
  3  select 100001 acc_code, date '2007-01-01' vdate, 5000 debit, cast(null as number(6)) credit from dual union all
  4  select 100001, date '2007-01-02', 6000, null from dual union all
  5  select 100001, date '2007-01-03', 9000, null from dual union all
  6  select 100001, date '2007-01-04', 75000, null from dual union all
  7  select 100002, date '2007-01-02', null, 6500 from dual union all
  8  select 100002, date '2007-01-03', null, 12870 from dual union all
  9  select 100002, date '2007-01-04', null, 5000 from dual union all
10  select 100002, date '2007-01-06', null, 9850 from dual
11  /
Tabel is aangemaakt.
SQL> var P_PARENTAC number
SQL> exec :P_PARENTAC := 100000
PL/SQL-procedure is geslaagd.
SQL> select d.acc_code "Account Code"
  2       , nvl(sum(d.debit),0) "Sum OF Debit"
  3       , nvl(sum(d.credit),0) "Sum of Credit"
  4    from details d
  5       , charts c
  6   where d.acc_code = c.acc_code
  7     and c.parentac = :P_PARENTAC
  8   group by d.acc_code
  9   order by d.acc_code
10  /
                          Account Code                           Sum OF Debit                          Sum of Credit
                                100001                                  95000                                      0
                                100002                                      0                                  34220
2 rijen zijn geselecteerd.Regards,
Rob.

Similar Messages

  • Parent-Child querying in Web Service 2.0

    Hello,
    Our team has just started to work on the integration from ws 1.0 to ws 2.0. One tuff issue that we meet and we are searching for help is:
    Since from ws 2.0 all objects are exposed at the same level and the attachements child objects are not exposed (compared to the ws 1.0 which attach childs along ListOfXXX with parents), we are wondering how then to querying these child objects now ? More explicitly, with knowing the parent object, how to retrieve its child objects ? Or it becomes impossible since ws 2.0 ?
    This issue is really confusing us now, and we did not find the answer from the new "Oracle Web Service On Demand Guilde v4.0".
    Any help/answer/comment/suggestion on this issue would be greatly appreciate !
    Fang

    Hi all,
    Thanks for your replies. Well at this point, i must say it's really a dispointment for the 2.0 release which is supposed to (at least seems suppose to) replace the previous one.
    Could you please give us an idea that is the query by chilid feature will be implement in future release and if it is when ?
    Thanks again for your clarifications.
    Fang

  • Parent Child Query

    I have records in the table in this format without any sequence
    Code Name Parent_Coe
    1000 ABC 0
    2000 ABC 0
    3000 ABC 0
    4000 ABC 0
    9000 ABC 0
    5000 ABC 1000
    6000 ABC 5000
    7000 ABC 6000
    8000 ABC 2000
    i want all child come under there parents just like this.
    Code Name Parent_Coe
    1000 ABC 0
    5000 ABC 1000
    6000 ABC 5000
    7000 ABC 6000
    2000 ABC 0
    8000 ABC 2000
    3000 ABC 0
    4000 ABC 0
    9000 ABC 0
    Query Please???

    SQL> ed
    Zapisano file afiedt.buf
      1  WITH d AS (
      2   SELECT 1000 c1, 'ABC' c2, 0 c3 FROM dual UNION ALL
      3   SELECT 2000, 'ABC', 0 FROM dual UNION ALL
      4   SELECT 3000, 'ABC', 0 FROM dual UNION ALL
      5   SELECT 4000, 'ABC', 0 FROM dual UNION ALL
      6   SELECT 9000, 'ABC', 0 FROM dual UNION ALL
      7   SELECT 5000, 'ABC', 1000 FROM dual UNION ALL
      8   SELECT 6000, 'ABC', 5000 FROM dual UNION ALL
      9   SELECT 7000, 'ABC', 6000 FROM dual UNION ALL
    10   SELECT 8000, 'ABC', 2000 FROM dual)
    11  SELECT * FROM d
    12   START WITH c3 = 0
    13   CONNECT BY PRIOR c1 = c3
    14*  ORDER SIBLINGS BY c1
    SQL> /
            C1 C2          C3
          1000 ABC          0
          5000 ABC       1000
          6000 ABC       5000
          7000 ABC       6000
          2000 ABC          0
          8000 ABC       2000
          3000 ABC          0
          4000 ABC          0
          9000 ABC          0
    9 wierszy zosta│o wybranych.
    SQL>

  • Parent-- Child result set required

    Hi Friends,
    I have below table
    TableA
    ParentColumn
    ChildColumn
    1
    abc
    1
    efg
    1
    ijk
    1
    lmn
    2
    aaa
    2
    bbb
    3
    xxx
    3
    ggg
    and I am looking for below result set.
    SomeColumnName
    1
    abc
    efg
    ijk
    lmn
    2
    aaa
    bbb
    3
    xxx
    ggg
    Please help me achieve this goal.
    THanks in advance
    Parixit

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. The useless picture you did post is a report and not a query!! The terms "child" and "parent" are from 1970's network DB and not RDBMS. You really have  no idea what you are doing at even the most basic level.
    Bad manners and total ignorance are not a substitute for actually learning 6o write SQL. Please come back when you have made an an effort on your own. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Parent child query help

    my requirement:
    3 columns in table
    column a    column b   data column
    10          9     
    13              10       acb
    12              13       rerer
    15          17     
    16              15      
    20          16     iiio
    output:
    column a    column b   data column
    13              10       acb
    20          16     iiioThanks.
    Edited by: user12988565 on Apr 14, 2010 1:59 PM
    Edited by: user12988565 on Apr 14, 2010 2:00 PM

    Hi All,
    Please let me know for any more details:
    column a    column b   data column
    10          9     
    13              10       acb
    12              13       rerer
    15          17     
    16              15      
    20          16     iiio
    output:
    column a    column b   data column
    13              10       acb
    20          16     iiiohow the output is reached at?
    1st set
    10 - 9
    13 - 10 acb -- data found, display the data. though for 13 there was rerer data in data column
    2nd set
    15 - 17
    16 - 15
    20 - 16 iiio -- data found display the data.
    Thanks.

  • Except function with parent child hierarchy using mdx query

    HI,
    I need to remove some items using mdx query in parent child hierarchy.
    I tried with below query,it is not removeing ,could you please help me.
    SELECT
    {[Measures].[Amount]} ON
    COLUMNS
     NonEmpty([Account].[Accounts].[Account Level 01],[Measures].[Amount])
    ON ROWS
    FROM (SELECT
    -Descendants({[Account].[Accounts].&[47]},,Leaves)
    } ON COLUMNS
    FROM [Adventure Works])
    indu

    Hi Indu,
    Why do you remove some itmes using
    Descendants function? Generally, we use FILTER function to achieve the requirement.
    WITH SET [CustomAccounts] AS
    FILTER ([Account].[Accounts].[Account Level 01].Members , [Account].[Accounts].CurrentMember.Name<>'Net Income')
    SELECT {[Measures].[Internet Sales Amount]} ON 0
    [CustomAccounts] ON 1
    FROM [Adventure Works]
    WITH SET [CustomAccounts] AS
    FILTER ([Account].[Accounts].[Account Level 01].Members , [Account].[Accounts].CurrentMember.Name='Net Income')
    SET [RemainingAccount] AS
    [Account].[Accounts].[Account Level 01]- [CustomAccounts]
    SELECT {[Measures].[Reseller Sales Amount]} ON 0
    [RemainingAccount] ON 1
    FROM [Adventure Works]
    Results.
    References.
    http://www.databasejournal.com/features/mssql/article.php/3306101/MDX-Essentials-Basic-Set-Functions-The-Filter-Function.htm
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/c0149678-97f2-4066-903f-7f9e9ff09b56/filtering-out-dimension-members-with-mdx?forum=sqlanalysisservices
    Regards,
    Charlie Liao
    If you have any feedback on our support,
    please click here.
    Charlie Liao
    TechNet Community Support

  • Query Help with Parent, Child, Child's Child

    Hi all,
    Need some help with a query.  I'm trying to create a stored procedure that is sort of like a Customer, Order, Order, Details.  In my situation the tables are different but nevertheless, I want to grab all the fields from the  Parent, Child,
    and Childs' Child, where the Parent.ParentID = @Parameter.  I tried this:
    CREATE PROCEDURE [dbo].[spGetCompleteProjectXML]
    @ProjectID int = 0
    AS
    SELECT *,
    (SELECT *,
    (SELECT *
    FROM PageControls
    WHERE (PageControls.ProjectPageID = ProjectPages.ProjectPageID))
    FROM ProjectPages
    WHERE (ProjectPages.ProjectID = @ProjectID))
    FROM Projects
    WHERE (ProjectID = @ProjectID)
    FOR XML AUTO, ELEMENTS
    RETURN 0
    I think I'm close, but it was my best effort.  Could someone help?
    thanks in advance

    Hi TPolo,
    Regarding your description, are you looking for a sample like below?
    CREATE TABLE customer(customerID INT, name VARCHAR(99))
    INSERT INTO customer VALUES(1,'Eric')
    INSERT INTO customer VALUES(2,'Nelson')
    CREATE TABLE orders(orderID INT,customerID INT)
    INSERT INTO orders VALUES(1,1);
    INSERT INTO orders VALUES(2,1)
    INSERT INTO orders VALUES(3,2)
    INSERT INTO orders VALUES(4,2)
    CREATE TABLE orderDetails(orderID INT,item VARCHAR(99))
    INSERT INTO orderDetails VALUES(1,'APPLE1')
    INSERT INTO orderDetails VALUES(1,'BANANA1')
    INSERT INTO orderDetails VALUES(2,'APPLE2')
    INSERT INTO orderDetails VALUES(2,'BANANA2')
    INSERT INTO orderDetails VALUES(3,'APPLE3')
    INSERT INTO orderDetails VALUES(3,'BANANA3')
    INSERT INTO orderDetails VALUES(4,'APPLE4')
    INSERT INTO orderDetails VALUES(4,'BANANA5')
    SELECT customer.customerID,customer.name,
    (SELECT orderId,
    SELECT item FROM orderDetails WHERE orderID=orders.orderID FOR XML AUTO,TYPE,ELEMENTS
    FROM orders Where customerID=customer.customerID FOR XML AUTO,TYPE,ELEMENTS)
    FROM customer WHERE customerID=1
    FOR XML AUTO,ELEMENTS
    DROP TABLE customer,orderDetails,orders
    If you have any feedback on our support, please click
    here.
    Eric Zhang
    TechNet Community Support

  • Parent child relation using query

    Hi,
    If i pass one parameter as a parent.It will
    retrieve all the child and subchild...
    but it will be retrieved by one single query.
    Is it possible?If possible pls give me an idea.
    I got the inner most child using stored procedure and recursive fn.
    But I couldnt get the child and subchild using
    single query....
    pls give an idea
    below i gave table for example
    Sno     Parent     Child
    1     MD     GM
    2     GM     Material manager
    3     GM     Production manager
    4     Production manager     Material staff
    5     Material staff     production staff
    6     production staff     Material student
    7     Material student     production student
    if i pass GM as a parent. it will retrieve
    material manager and production manager...but it will be worked in single query
    Thanks

    Hi,
    SELECT * FROM t11
    START WITH parent='GM'
    CONNECT BY PRIOR child=parent
    Out put :-
    2 GM Material manager
    3 GM Production manager
    4 Production manager Material staff
    5 Material staff production staff
    6 production staff Material student
    7 Material student production student
    Pavan Kumar N

  • Incorrect query forms in parent child relation

    Hello
    I am using jdev of RUP3 (Release 4) which is 11.1.1.6.2 and have following scenario
    I have a ParentVO (ProfileVO) and a child VO(CreditReceiversVO) (child VO is basically extended from another VO not in this application and included as a jar library).
    There a VL between ParentVO and ChildVO 1:* with two attributes ord_id and rule_id
    On UI these two VO instances are dropped as parent child and I get exception on running page in logs saying RuleAssignementEO.ORG_ID invalid identifier.
    Looking into the query formed by BC4J I see it as below which is clearly wrong as the alias RuleAssignmentEO is not visible for the outermost where clause. Please advise
    "SELECT count(1) FROM (SELECT * FROM (SELECT /*+ FIRST_ROWS(10) */
    RuleAssignmentsEO.RULE_ASSIGNMENT_ID,
    RuleAssignmentsEO.OBJECT_VERSION_NUMBER,
    RuleAssignmentsEO.RULE_ID,
    RuleAssignmentsEO.ASSIGNED_OBJECT_ID,
    RuleAssignmentsEO.ASSIGNED_OBJECT_TYPE,
    RuleAssignmentsEO.ORG_ID,
    RuleAssignmentsEO.ROLE_ID,
    RuleAssignmentsEO.START_DATE,
    RuleAssignmentsEO.END_DATE,
    RuleAssignmentsEO.SPLIT_PCT,
    RuleAssignmentsEO.REVENUE_TYPE,
    RuleAssignmentsEO.ROLLUP_FLAG,
    RuleAssignmentsEO.CREATED_BY,
    RuleAssignmentsEO.CREATION_DATE,
    RuleAssignmentsEO.LAST_UPDATED_BY,
    RuleAssignmentsEO.LAST_UPDATE_DATE,
    RuleAssignmentsEO.LAST_UPDATE_LOGIN,
    RuleAssignmentsEO.ATTRIBUTE_CATEGORY,
    RuleAssignmentsEO.ATTRIBUTE1,
    RuleAssignmentsEO.ATTRIBUTE2,
    RuleAssignmentsEO.ATTRIBUTE3,
    RuleAssignmentsEO.ATTRIBUTE4,
    RuleAssignmentsEO.ATTRIBUTE5,
    RuleAssignmentsEO.ATTRIBUTE6,
    RuleAssignmentsEO.ATTRIBUTE7,
    RuleAssignmentsEO.ATTRIBUTE8,
    RuleAssignmentsEO.ATTRIBUTE9,
    RuleAssignmentsEO.ATTRIBUTE10,
    RuleAssignmentsEO.ATTRIBUTE11,
    RuleAssignmentsEO.ATTRIBUTE12,
    RuleAssignmentsEO.ATTRIBUTE13,
    RuleAssignmentsEO.ATTRIBUTE14,
    RuleAssignmentsEO.ATTRIBUTE15,
    RuleAssignmentsEO.GROUP_MEMBER_CREDIT_FLAG,
    RuleAssignmentsEO.SUMMARY_FLAG,
    ParticipantEO.PARTICIPANT_NAME,
    ParticipantEO.PARTICIPANT_ID
    FROM CN_RS_RULE_ASSIGNMENTS_ALL RuleAssignmentsEO, CN_SRP_PARTICIPANT_HDR_RO_V ParticipantEO
    WHERE RuleAssignmentsEO.ASSIGNED_OBJECT_ID = ParticipantEO.PARTICIPANT_ID(+)) QRSLT WHERE RuleAssignmentsEO.RULE_ID = :Bind_RuleId AND RuleAssignmentsEO.ORG_ID = :Bind_OrgId) "
    Edited by: Vik2 on Oct 23, 2012 11:30 AM

    invalid identifier means ,it representating that field currently not available in db-table.
    so please refer db-table. whether field avialable or not?.
    edited lately:
    djbo.debugoutput=console did you use this :) it will say the query is send to server.
    Edited by: user707 on Oct 22, 2012 11:58 PM

  • Parent Child Relationship in the table to be queried.

    Hi guys,
    I have the below query.
    Table 1:
    Column_name Reference
    Value1 Value1
    Value2 Value1
    Table 2:
    Column_name Attributes(child Elements)
    Value1 Child1
    Value1 Child2
    Now my query is to retrieve records as below using both the tables.
    Value1
    Value1.Child1
    Value1.Child2
    Value2
    Value2.Child1
    Value2.Child2
    How can I get such ?
    Regards,
    SQL Developer.

    Hi,
    As Alex said, you should have tried by joining them.
    With Parent As (
    select 'Value1' p_col1,'Value1' P_col2 from dual union all
    select 'Value2','Value1' from dual),
    child as (
    select 'Value1' c_col1,'Child1' c_col2 from dual union all
    select 'Value1','Child2' from dual)
    -- End of sample data
    select p_col1,null c_col2 from parent
    union
    select p_col1,c_col2 from parent,child
    where p_col2=c_col1
    order by p_col1,c_col2 desc
    PRAZY@11gR1> /
    P_COL1 C_COL2
    Value1
    Value1 Child2
    Value1 Child1
    Value2
    Value2 Child2
    Value2 Child1
    6 rows selected.
    Elapsed: 00:00:00.03Regards,
    Prazy

  • Parent child level Query

    Hi All,
    I have a requirement to pull parent child partynames from hz_parties,hz_relationships table
    I need output like below:
    Partyname, partynumber,immediateparent(partyname),globlapartyname..
    could you please suggest me.I am new to EBS..
    Thanks
    Bhavana

    Any Help please....
    Edited by: user13689917 on Mar 9, 2011 2:32 PM
    Edited by: user13689917 on Mar 9, 2011 2:33 PM

  • Xcelsius Parent/Child solution and BI Widgets

    Hi,
    Does anyone know if BI Widgets supports Xcelsius SWF files that have been created using the scaled method; i.e. Using a Parent SWF linked to Child SWFs which are loaded into the slideshow component using the documentDownload? URL and a selector.
    I am trying to access such a dashboard solution and deploy it onto the users desktop.
    The dashboard works when accessed through Infoview using both the below relative and actual URL's i.e.
    "../../../Xcelsius/opendoc/documentDownload?sIDType=CUID&iDocID=AfYquYuuqxJPjbXesBEC6d4&sKind=Flash&CELogonToken="&$C$9
    Or
    "http://bo1:8066/Xcelsius/opendoc/documentDownload?sIDType=CUID&iDocID=AfYquYuuqxJPjbXesBEC6d4&sKind=Flash&CELogonToken="&$C$9
    The problem is I can not get the child SWF to download into the Slideshow component in the Parent SWF when it has been published to the dashboard using BI Widgets.
    Questions:
    1. Does anyone know if BI Widgets supports SWF Parent/child u201Cscale upu201D solution
    2. If so what should the URL be to call the children into the slideshow??
    Thanks in advance.
    Pen.

    Hi Alan,
    Thanks for your response.
    I receive no error messages; when I try to load a child swf into the parent slideshow component I see only a 0% progress bar in the slideshow component. I have also tried also using the OpenDocuemnt.jsp and when I try this in the above aforementioned URLs I get a 100% progress bar - but nothing else. i.e.It never displays the child swfs and nor does OpenDocument.jsp work in Infoview.  The documentDownload? option does work in infoview but it does not work in BI Widgets.
    I have also visited the Flash settings manager site and set the Global Security options to u201CAlways allowu201D  and have added the BOE servers and my C:\ and Desktop to the u201Callow locationsu201D.
    When you say that Flash will not let you access files off the desktop what exactly do you mean? I'm not sure if this relates to me as I am trying to access files from BOE XI 3.1.
    Thanks for the advice; I will also post this issue on the Xcelsius forum.
    Regards,
    Penny.

  • Querying parent child sets

    Hi
    I have a cube with a dimension that has a value based hierarchy (id, description,parent)
    Is it possible to query the cube to get parent child sets ?
    I want the result set to look like
    Member Value Parent
    Parent_1 Measure_Value NULL
    Child_1.1 Measure_Value Parent_1
    Child_1.2 Measure_Value Parent_1
    Parent_2 Measure_Value NULL
    Child_2.1 Measure_Value Parent_2
    Child_2.2 Measure_Value Parent_2
    Also I am using a java front end,so I would like to do some pagination
    So I would like say 1st 50 sets , 2nd 50 sets and so on

    Cube Materialized Views are only created if you enable them and they are also only compatible with level based hierarchies. So MVs are not appropriate in your case.
    If you are generating your own SQL then you could consider a hybrid approach by combining OLAP DML and SQL to get the explicit list of members. First execute the following OLAP DML.
    LIMIT my_dim TO 'Parent_1' 'Parent_2'
    LIMIT my_dim ADD DESCENDANTS USING my_dim_parentrel
    SORT my_dim HIERARCHY my_dim_parentrelNow get the dimension members via either OLAP DML (e.g. REPORT command) or running SQL after the limit above. This gives you the explicit list of members that you can feed into a subsequent query.
    SELECT dim_key, ...
    FROM my_dim_view, cube_view
    WHERE
      <join condition>
      AND dim_key IN (...list from report command...}
      Make sure you set status back via ALLSTAT after getting the list or it will change results later.

  • Retrieve Parent Child Sub-Child recors in SQL Query

    I've a self reference table and it has Parent-Child-Subchild relation. I'm getting an output (from second answer http://stackoverflow.com/questions/16031000/get-records-containing-all-the-child-records-in-sql-server) as expected, but it's
    displaying results in below format.
    <parent id> - <name> - <code>
    <child id> - <name> - <code>
    <child id> - <name> - <code>
    <child id> - <name> - <code>
    <child id> - <name> - <code>
    <sub child id> - <name> - <code>
    <sub child id> - <name> - <code>
    <sub child id> - <name> - <code>
    I want to display the results like in below format with applying some indent style to distinguish parent\ child\sub-child relationship.
    <parent id> - <name> - <code>
    <child id> - <name> - <code>
    <child id> - <name> - <code>
    <sub child id> - <name> - <code>
    <sub child id> - <name> - <code>
    <child id> - <name> - <code>
    <child id> - <name> - <code>
    <sub child id> - <label> - <code>
    <child id> - <name> - <code>
    <child id> - <name> - <code>
    Please assist me on foumulating results as expected.

    BOL has a good example of doing this in the CTE topic.  See http://technet.microsoft.com/en-us/library/ms175972%28v=sql.105%29.aspx Here is a slightly modified
    version of what is in BOL.
    CREATE TABLE #MyEmployees
    EmployeeID smallint NOT NULL,
    FirstName nvarchar(30) NOT NULL,
    LastName nvarchar(40) NOT NULL,
    Title nvarchar(50) NOT NULL,
    DeptID smallint NOT NULL,
    ManagerID int NULL,
    CONSTRAINT PK_EmployeeID PRIMARY KEY CLUSTERED (EmployeeID ASC)
    -- Populate the table with values.
    INSERT INTO #MyEmployees VALUES
    (1, N'Ken', N'Sánchez', N'Chief Executive Officer',16,NULL)
    ,(273, N'Brian', N'Welcker', N'Vice President of Sales',3,1)
    ,(274, N'Stephen', N'Jiang', N'North American Sales Manager',3,273)
    ,(275, N'Michael', N'Blythe', N'Sales Representative',3,274)
    ,(276, N'Linda', N'Mitchell', N'Sales Representative',3,274)
    ,(285, N'Syed', N'Abbas', N'Pacific Sales Manager',3,273)
    ,(286, N'Lynn', N'Tsoflias', N'Sales Representative',3,285)
    ,(16, N'David',N'Bradley', N'Marketing Manager', 4, 273)
    ,(23, N'Mary', N'Gibson', N'Marketing Specialist', 4, 16);
    ; WITH DirectReports(Name, Title, EmployeeID, EmployeeLevel, Sort)
    AS (SELECT CONVERT(varchar(255), e.FirstName + ' ' + e.LastName),
    e.Title,
    e.EmployeeID,
    1,
    CONVERT(varchar(255), e.FirstName + ' ' + e.LastName)
    FROM #MyEmployees AS e
    WHERE e.ManagerID IS NULL
    UNION ALL
    SELECT CONVERT(varchar(255), REPLICATE (' ' , EmployeeLevel) +
    e.FirstName + ' ' + e.LastName),
    e.Title,
    e.EmployeeID,
    EmployeeLevel + 1,
    CONVERT (varchar(255), RTRIM(Sort) + '| ' + FirstName + ' ' +
    LastName)
    FROM #MyEmployees AS e
    JOIN DirectReports AS d ON e.ManagerID = d.EmployeeID
    SELECT EmployeeID, Name, Title, EmployeeLevel
    FROM DirectReports
    ORDER BY Sort;
    GO
    drop table #MyEmployees;
    Tom

  • The Parent-Child Hierarchy can't be queried in any intermediate node

    Hi All,
    I've created a Parent-Child Hierarchy with Obiee 11g(11.1.1.3).
    I can use the filter to select any Root-Node and it can be expanded correctly.But if I choose any intermediate node,it can't be expanded.Then what can I do?
    Thanks in advance!
    Edited by: Needn on 2011-9-8 下午8:42

    Thx for your advice,but my qusetion has not been solved.
    I don't know how to use these function in the analytics page.Must I modify its default SQL and apply mine?
    Its default SQL like the following ,then how can I modify it to achieve my purpose?
    SELECT s_0, s_1, s_2, s_3, s_4 FROM (
    SELECT
    *0 s_0,*
    *"model"."DIM_PROD_COST_CATEGORY"."CATEGORY_NAME" s_1,*
    CASE WHEN ISLEAF("model"."DIM_PROD_COST_CATEGORY"."DIM_PROD_COST_CATEGORYDim") THEN 1 ELSE 0 END s_2,
    IDOF("model"."DIM_PROD_COST_CATEGORY"."DIM_PROD_COST_CATEGORYDim") s_3,
    PARENT("model"."DIM_PROD_COST_CATEGORY"."DIM_PROD_COST_CATEGORYDim") s_4
    FROM "model"
    WHERE
    ISROOT("model"."DIM_PROD_COST_CATEGORY"."DIM_PROD_COST_CATEGORYDim")
    *) djm ORDER BY 1*

Maybe you are looking for

  • Cannot Complete Installation of Vista with Mac Pro and Boot Camp

    I only have one hard drive with my Mac Pro, and I partitioned the drive into two sections with boot camp and restarted with my Vista 64 bit Ultimate CD. I have tried formatting the partition with Vista and it still gives me the dreaded error message

  • Last attempt to fix this slow net or I'm leaving.

    As I'm typing this message out, I can hardly load anything on BT Infinity due to constant disconnections and spikes. For the past 1 month I've been having issues of my internet spiking consistently and disconnecting every few minutes and it's been re

  • Can't go online

    Hello, I finally have the new iPod touch, and it's fabulous. I tried several times to connect to internet via Wi-Fi, but it just doesn't work... Why? What is the problem? I tried to go on internet with the wi-fi with my laptop, and it's ok, but I can

  • Can iphone ios 8.2 get a trojan horse of some sort?

    I texted my sister telling her my daughter was invited to MV etc and when I went to open her reply, in the box it would say, "I want to go" as if I wrote that and I didn't. Another example is, I texted my sister this, "Rachael filed for divorce today

  • Installing Weblogic Admin Server as service -  service won't start

    I'm installing Weblogic Admin Server as a Service in Weblogic 10 on a Windows 2008 R2 box. The service installs correctly, but when I start it, it immeidately stops with this error: "The <service name> service on Local Computer started and then stopp