Query to retrieve 2 level of supervisors

Hi all,
I am using the following query to retrieve the people who is being supervised for a given person_id... Is there any way to modify this query (below) in order to get two levels of employees? something like:
Supervisor 1
Employee 1
Employee 2
Employee 3
Supervisor 2
Employee 4
Employee 5
Employee 6
The query is working if I pass the person_id of Supervisor 1 for example I would get Employee 1 2 and 3. But if I pass a person id which of higher hierarchy I will just get Supervisor 1 Supervisor 2 ... And I need all the people (just two levels down)
select distinct * from(
select distinct ppf.first_name||' '||ppf.last_name
, ppf.last_name
, fu.user_name
, fu.user_id
, ppf.person_id
, papf.person_id supervisor_id
, pi.image_id
, initcap(hla.description) LOCATION
, pb.NAME pay_basis_name
, pax.grade_id
, haou.name
, employment_category
, ppos.date_start
from per_assignments_x pax
, per_grade_definitions pgd
, per_people_x ppf
, fnd_user fu
, per_all_people_f papf
, per_images pi
, hr_locations_all hla
, per_pay_bases pb
, hr_all_organization_units haou
, per_periods_of_service ppos
where ppf.person_id = pax.person_id
and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
and fu.person_party_id = papf.party_id
and pax.supervisor_id =papf.person_id
and pi.parent_id (+) = ppf.person_id
and pi.table_name(+) = 'PER_PEOPLE_F'
and pax.person_id = ppf.person_id
and hla.location_id (+)= pax.location_id
AND ppf.current_employee_flag = 'Y'
AND pb.pay_basis_id = pax.pay_basis_id
AND haou.organization_id = pax.organization_id
AND ppos.person_id = ppf.person_id
AND pax.grade_id = pgd.grade_definition_id
AND papf.person_id = :inPersonId
UNION ALL
select ppf.first_name||' '||ppf.last_name
, ppf.last_name
, fu.user_name
, fu.user_id
, ppf.person_id
, papf.person_id supervisor_id
, pi.image_id
, initcap(hla.description) LOCATION
, pb.NAME pay_basis_name
, pax.grade_id
, haou.name
, employment_category
, ppos.date_start
from per_people_x ppf
, per_grade_definitions pgd
, fnd_user fu
, per_all_people_f papf
, HR_WORKING_PERSON_LISTS HWPL
, per_images pi
, per_assignments_x pax
, hr_locations_all hla
, per_pay_bases pb
, hr_all_organization_units haou
, per_periods_of_service ppos
where
trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
and fu.person_party_id = papf.party_id
AND HWPL.owning_person_id = papf.person_id
and hwpl.selected_person_id = ppf.person_id
AND pi.parent_id (+) = ppf.person_id
and ppf.current_employee_flag = 'Y'
and pax.person_id = ppf.person_id
AND hla.location_id (+)= pax.location_id
AND pb.pay_basis_id = pax.pay_basis_id
AND haou.organization_id = pax.organization_id
AND ppos.person_id = ppf.person_id
AND pax.grade_id = pgd.grade_definition_id
AND papf.person_id = :inPersonId
)order by last_name

Hola Alejandro,
you can play a little bit around with the one below you find more confortable with.
/* multi level */
select level
,assignment_number
,assignment_id
,supervisor_id
,(select full_name from per_people_x where person_id = pax.person_id)
,sys_connect_by_path( (select employee_number from per_people_x where person_id = pax.person_id), ' --> ')
from per_assignments_x pax
where primary_flag = 'Y'
connect by prior person_id = supervisor_id
start with person_id = 1523
/* level 2 only */
select (select full_name from per_people_x where person_id = pax1.person_id)
,(select full_name from per_people_x where person_id = pax2.person_id)
from per_assignments_x pax1
,per_assignments_x pax2
where pax1.supervisor_id = 1523
and pax1.primary_flag = 'Y'
and pax1.person_id = pax2.supervisor_id
and pax2.primary_flag = 'Y'

Similar Messages

  • Need efficient SQL query to retrieve data for MLM website

    Table cd_members
    MemberID LeftID RightID
    1 2 3
    2 4 5
    3 6 7
    4 8 -
    5 - -
    6 - -
    7 - -
    8 9 10
    9 - -
    10 - -
    i want to execute a query to retrieve downline of a member say MemberID 2
    o/p should be Records with MemberID 4,5,8,9,10
    i am using this query but don't know how to start from MembeID=2
    select a.memberid, a.tradingid, a.refid, a.parentid, a.node, a.leftid, a.rightid, b.memberid from cd_members a, cd_members b
    where (a.leftid=b.memberid or a.rightid=b.memberid)

    Again, assuming that the number of levels is known, you can just do N self joins (note that I intentionally go one level further than necessary in this case
    SQL> ed
    Wrote file afiedt.buf
      1  with t
      2    as
      3   (
      4      select 1 person, 2 left, 3 right from dual union all
      5      select 2, 4, 5 from dual union all
      6      select 3, 6, 7 from dual union all
      7      select 4, 8, null from dual union all
      8      select 5, null, null from dual union all
      9      select 6, null, null from dual union all
    10      select 7, null, null from dual union all
    11      select 8, 9, 10 from dual union all
    12      select 9, null, null from dual union all
    13      select 10, null, null from dual
    14   )
    15   select t1.left, t1.right, t2.left, t2.right, t3.left, t3.right, t4.left, t
    4.right
    16     from t t1,
    17          t t2,
    18          t t3,
    19          t t4
    20    where t1.person = 2
    21      and t1.left = t2.person(+)
    22      and t2.left = t3.person(+)
    23*     and t3.left = t4.person(+)
    SQL> /
          LEFT      RIGHT       LEFT      RIGHT       LEFT      RIGHT       LEFT
         RIGHT
             4          5          8                     9         10Justin

  • Web Analysis Error -- Error while executing query and retrieving data

    Regarding Web Analysis:
    We have a number of reports that we created. yesterday they were all working fine. today we try to open them and most are generating an error.
    The error is:
    Error while executing query and retrieving data.; nested exception is:
    com.hyperion.ap.APException: [1033] Native:
    1013033[Thu Oct 22 09:08:17
    2009]server name/application name/database name/user name/Error91013033)
    ReportWriter exit abnormally
    Does anyone have any insight into what is going on?
    My version information is:
    Hyperion System 9 BI+ Analytic Administration Services 9.3.0.1.1 Build 2
    Web Analysis 9.3.0.0.0.286
    Thanks in advance for your help.
    DaveW

    Hi,
    And also click on check option by opening the query in Query designer,as Mr . Arun suggested.
    And if you get any error in checking, see the long message(detail).
    With rgds,
    Anil Kumar Sharma .P

  • Query to retrieve the number of transactions done in every 1 hour for last

    Hi,
    Could anyone help in writing a query to retrieve the number of transactions done in every 1 hour for last month.
    Case:
    I/P
    Cases Timestamp1
    case1 01-01-2008 00:00:01
    case2 01-01-2008 00:01:01
    case3 01-01-2008 01:00:01
    case1 01-01-2008 01:02:01
    case4 01-01-2008 01:10:01
    case5 02-01-2008 02:00:01
    case6 02-01-2008 02:10:01
    case7 02-01-2008 23:00:01
    case.. 31-01-2008 24:00:00
    O/P
    from time to_time cases
    01-01-2008 00:00:00 01-01-2008 01:00:00 2
    01-01-2008 01:00:01 01-01-2008 02:00:00 3
    etc
    Any help really appreciated

    We can do this using analytical functions
    Following is what I did:
    create table timestamp1 (ts date)
    select *from timestamp1
    30/10/2008 15:41:13
    30/10/2008 15:41:05
    30/10/2008 15:40:03
    30/10/2008 14:58:26
    30/10/2008 14:29:45
    30/10/2008 13:17:48
    30/10/2008 08:29:50
    30/10/2008 06:05:51
    30/10/2008 03:41:52
    30/10/2008 02:29:54
    select distinct to_char(ts,'hh24') frmhrs,
    to_char(ts,'hh24')+1 tohrs, count(ts) OVER (order by to_number(to_char(ts,'hh24')) RANGE (1/24) PRECEDING )
    from timestamp1
    where trunc(ts)=trunc(sysdate) -- I added this just to make sure I get for today's data
    order by frmhrs
    FRMHRS     TOHRS     CNT
    02     3     1
    03     4     1
    06     7     1
    08     9     1
    13     14     1
    14     15     2
    15     16     3
    You can customizeas per ur need.

  • Customer Exit in query on aggregation level

    Hi,
    I try to have variables filled with a customer exit.
    The coding of the customer exit is correct, this have been tested in queries on multiproviders.
    Unfortunately it is not working when these variables are used on level of aggregation levels.
    What I would like to achieve:
    We have some planning queries on aggregation levels. Different users can plan on the same query (and aggregation level), but not for the same set of data. Therefore the query should be restricted to the authorized values. Unfortunately we can not switch to the new authorization concept (analysis authorizations) yet, but we already need this functionality very soon.
    The customer exits are the only possible option. Unfortunately it seems that the customer exits are not being executed when the variables are used in queries on aggregation levels.
    The variables are not ready for input and should be filled in I_STEP = 2
    Is this normal? If so, is there a work around?
    Thanks in advance for quick replies!
    Kind regards,
    Bart

    Hi,
    You can debug your query by putting the break-point in your exit code and execute the query in RSRT. This way you will be able to find if your customer exit is actually being called or not. If it is being called then there can be some logical problem with your code due to which the variable values are not getting populated.
    Regards,
    Deepti

  • Query to retrieve list of ledgers accessible for a given Applications User

    We've a requirement to find the list of the accessible ledgers for a given Oracle Apps User.I'm from Oracle ATG team,not familiar with GL terminologies. Can someone help with the query to retrieve the ledgers accessible for a given user.In our code flow, we may not have the complete applications context. Is it possible to retrieve that list only with the username. If so, how to do that? Do i need to access some profile values?
    Thanks,
    Senthil

    select * from usr where usr.usr_key not in (
    select usr.usr_key from oiu, usr, obi, obj, ost
    where oiu.usr_key=usr.usr_key
    and oiu.obi_key=obi.obi_key
    and obi.obj_key=obj.obj_key
    and obj.obj_name = :obj_name
    and oiu.ost_key=ost.ost_key
    and ost.ost_status not in ('Revoked'))
    -Kevin

  • Query to retrieve Identical names, same birth dates

    I have a table with these fields:
    table1 definition
    (ID varchar2(10),
    name1 varchar2(50),
    name2 varchar2(50),
    name3 varchar2(50),
    name4 varchar2(50),
    birthdt date)
    I need to write a query to retrieve the id's of those people that have identical first and last names AND were born on the same date. note that name is composed of four parts.
    I am trying this query
    (select id from table1 group by name1,name4,birthdt having count(name1)>1 and count(name4)>1 and count(birthdt)>1). I am not getting correct results.
    Any help appreciated.
    Ammar

    ¿...Doh...how could I miss that? smacks forehead
    Thanks ( for the N-th time ;) ) for setting straight, Solomon.
    Guess I wasn't completely recovered from yesterday ;)
    However, the basic approach wasn't too bad ;)
    But ofcourse the 'select *' should be 'select id'
    Using testdata:
    SQL> with table1 as ( -- generating sample data as I should have done in the first place:
      2  select 1 id, 'John' name1, 'James' name2, 'Joe' name3, 'Jameson' name4, to_date('15-05-1989','dd-mm-yyyy') birthdt from dual union all
      3  select 2 id, 'John' name1, 'James' name2, 'Joe' name3, 'Jackson' name4, to_date('15-05-1989','dd-mm-yyyy') birthdt from dual union all
      4  select 3 id, 'John' name1, 'James' name2, 'Joe' name3, 'Jameson' name4, to_date('25-05-1989','dd-mm-yyyy') birthdt from dual union all
      5  select 4 id, 'Zlad' name1, 'James' name2, 'Joe' name3, 'Jameson' name4, to_date('15-05-1989','dd-mm-yyyy') birthdt from dual union all
      6  select 5 id, 'John' name1, 'James' name2, 'Joe' name3, 'Jameson' name4, to_date('15-05-1989','dd-mm-yyyy') birthdt from dual
      7  )
      8  --
      9  -- actual query
    10  --
    11  select id
    12  from ( select id
    13         ,      name1
    14         ,      name2
    15         ,      name3
    16         ,      name4
    17         ,      birthdt
    18         ,      count(*) over (partition by name1, name2, name3, name4, birthdt) recs
    19         from   table1
    20       )
    21  where recs > 1;
            ID
             1
             5

  • Query to retrieve all saved user queries?

    Hi,
    In which table are the user queries saved?
    How can I write a query to retrieve all the user created queries?
    I need to copy all the user queries which are implemented in 1 client implementation to a different client's implementation.
    Thanks.

    Hi Rajesh
    Try This query
    select QName,QString from OUQR .
    You can use the quick copy option if you are using SAP version 9 and if lower you can use the copy express addon..
    SAP Business One 9 - Implemenation Center  Quick Copy  
    Hope Helpful
    Regards
    Kennedy

  • Query to retrieve all unreconciled BP account transactions

    Hi, can anyone help me to formulate a SQL query to retrieve only the unreconciled transactions from a business partner account.  In other words all the records that display in the account balance enquiry when you tick the "Display Unreconciled Trans. Only" box.

    Hi all,
    No one has been able to help with this one.  It appears to me there should be a simple solution somewhere.  Can anyone be a hero and answer this?
    I am querying the JDT1 table to get the transactions but I get everything and I want to identify only the ones that have not yet been reconciled.
    Cheers,
    Greg.

  • Query to retrieve user Authorizations

    Dear Experts,
    Is there anyone with a query to retrieve user names and their respective authorizations.
    Regards

    As now are aware that Authorization table is not exposed,you can export the authorization as suggested by one of the forum member.
    When Exporting the Authorisation the list of user name will be imported first and then the list of authorisation second.
    In order to have all the authorisations you will need to expand all the menu and sub menu.
    Adminitstration -> system initialisation -> System initialisation -> Authorisations -> General authorisations
       1. In the Authorisations window
       2. Click on expand
       3. With the Authorisations' window active click on Excel icon or go to File -> Export -> Export to MS Excel
       4. In the first 'Save as' window opening
       5. Name your 'User' file and select the relevant folder
       6. At the system message popping :'Do you want to export currency symbols ?'
       7. Click independently on 'Yes' or 'No'.
       8. A security warning message will appear.
       9. Click on 'Enable Macros'
      10. A second 'Save as' window is opened.
      11. Name your 'Authorisations list' file differently.
      12. Execute again step 6 to 9
    The two files will then open. One with the list of users one with the list of authorisations

  • Query to retrieve the records which have more than one assignment_id

    Hello,
    I am trying to write a query to retrieve all the records from the table per_all_assignments_f which has more than one different assignment_id for each person_id. Below is the query i have written but this retrieves the records even if a person_id has duplicate assignment_id's but i need records which have more than one assignement_id with no duplicates for each person_id
    select assignment_id ,person_id, assignment_id
    From per_all_assignments_f
    having count(assignment_id) >1
    group by person_id, assignment_id
    Thank You.
    PK

    Maybe something like this?
    select *
    From   per_all_assignments_f f1
    where  exists (select 1
                   from   per_all_assignments_f f2
                   where  f2.person_id = f1.person_id
                   and    f2.assignment_id != f1.assignment_id
                  );Edited by: SomeoneElse on May 7, 2010 2:23 PM
    (you can add a DISTINCT to the outer query if you need to)

  • SQL query to retrieve totals from "supporting Details"

    We've had a strange issue where the totals from the supporting details aren't adding up to the value submitted in essbase.
    In effect our RDMS is out of sync with Planning.
    In order to remedy this, I'm trying to build a SQL query to retrieve the value of the supporting details.
    Here is my Sql statement so far :
    SELECT
    HO1.OBJECT_NAME SCENARIO,
    HO2.OBJECT_NAME ACCOUNT,
    HO3.OBJECT_NAME ENTITY,
    HO4.OBJECT_NAME Month,
    HO5.OBJECT_NAME Version,
    HO6.OBJECT_NAME Currency,
    HO7.OBJECT_NAME Year,
    HO8.OBJECT_NAME Project,
    HO10.OBJECT_NAME CC,
    HO12.OBJECT_NAME Grplcl,
    HO13.OBJECT_NAME Product,
    HO15.OBJECT_NAME SalesRegion,
    HO16.OBJECT_NAME ContractAnalysis,
    HO17.OBJECT_NAME IC,
    SUM(NVL(HCDI.VALUE,0)) AMOUNT
    FROM hsp_column_detail HCD,
    hsp_column_detail_ITEM HCDI,
    HSP_OBJECT HO1,
    HSP_OBJECT HO2,
    HSP_OBJECT HO3,
    HSP_OBJECT HO4,
    HSP_OBJECT HO5,
    HSP_OBJECT HO6,
    HSP_OBJECT HO7,
    HSP_OBJECT HO8,
    HSP_OBJECT HO10,
    HSP_OBJECT HO12,
    HSP_OBJECT HO13,
    HSP_OBJECT HO15,
    HSP_OBJECT HO16,
    HSP_OBJECT HO17
    WHERE hcd.detail_id = hcdi.detail_id
    AND hcd.dim1 = ho1.object_id
    AND hcd.dim2 = ho2.object_id
    AND hcd.dim3 = ho3.object_id
    AND hcd.dim4 = ho4.object_id
    AND hcd.dim5 = ho5.object_id
    AND hcd.dim6 = ho6.object_id
    AND hcd.dim7 = ho7.object_id
    AND hcd.dim8 = ho8.object_id
    AND hcd.dim10 = ho10.object_id
    AND hcd.dim12 = ho12.object_id
    AND hcd.dim13 = ho13.object_id
    AND hcd.dim15 = ho15.object_id
    AND hcd.dim16 = ho16.object_id
    AND hcd.dim17 = ho17.object_id
    and hcdi.generation = 0
    GROUP BY HO1.OBJECT_NAME, HO2.OBJECT_NAME, HO3.OBJECT_NAME, HO4.OBJECT_NAME,
    HO5.OBJECT_NAME,
    HO6.OBJECT_NAME,
    HO7.OBJECT_NAME,
    HO8.OBJECT_NAME,
    HO10.OBJECT_NAME,
    HO12.OBJECT_NAME,
    HO13.OBJECT_NAME,
    HO15.OBJECT_NAME,
    HO16.OBJECT_NAME,
    HO17.OBJECT_NAME
    ORDER BY HO1.OBJECT_NAME, HO3.OBJECT_NAME, HO2.OBJECT_NAME

    This query works using PL SQL and has been used on Oracle 9.2.3.
    Cheers,
    Jeremie
    Here is the Query:
    set serveroutput on;
    set serveroutput on size 1000000;
    --set buffer_size 10000000;
    --set line_size 2000;
    --DBMS_OUTPUT.size = 2000000;
    DECLARE
    CURSOR BUDGET_HEADERS_CU IS
    SELECT
    hcd.detail_id,
    HO1.OBJECT_NAME SCENARIO,
    HO2.OBJECT_NAME ACCOUNT,
    HO3.OBJECT_NAME ENTITY,
    HO4.OBJECT_NAME Month,
    HO5.OBJECT_NAME Version,
    HO6.OBJECT_NAME Currency,
    HO7.OBJECT_NAME Year,
    HO8.OBJECT_NAME Project,
    HO10.OBJECT_NAME CC,
    HO12.OBJECT_NAME Grplcl,
    HO13.OBJECT_NAME Product,
    HO15.OBJECT_NAME SalesRegion,
    HO16.OBJECT_NAME ContractAnalysis,
    HO17.OBJECT_NAME IC,
    hcd.dim1 SCENARIO_id,
    hcd.dim2 ACCOUNT_id,
    hcd.dim3 ENTITY_id,
    hcd.dim4 Month_id,
    hcd.dim5 Version_id,
    hcd.dim6 Currency_ID,
    hcd.dim7 Year_ID,
    hcd.dim8 Project_ID,
    hcd.dim10 CC_ID,
    hcd.dim12 Grplcl_ID,
    hcd.dim13 Product_ID,
    hcd.dim15 SalesRegion_ID,
    hcd.dim16 ContractAnalysis_ID,
    hcd.dim17 IC_ID
    FROM hsp_column_detail HCD, /*hsp_column_detail_item HCDi,*/
    HSP_OBJECT HO1,
    HSP_OBJECT HO2,
    HSP_OBJECT HO3,
    HSP_OBJECT HO4,
    HSP_OBJECT HO5,
    HSP_OBJECT HO6,
    HSP_OBJECT HO7,
    HSP_OBJECT HO8,
    HSP_OBJECT HO10,
    HSP_OBJECT HO12,
    HSP_OBJECT HO13,
    HSP_OBJECT HO15,
    HSP_OBJECT HO16,
    HSP_OBJECT HO17
    WHERE /*hcd.detail_id = hcdi.detail_id
    AND*/ hcd.dim1 = ho1.object_id
    AND hcd.dim2 = ho2.object_id
    AND hcd.dim3 = ho3.object_id
    AND hcd.dim4 = ho4.object_id
    AND hcd.dim5 = ho5.object_id
    AND hcd.dim6 = ho6.object_id
    AND hcd.dim7 = ho7.object_id
    AND hcd.dim8 = ho8.object_id
    AND hcd.dim10 = ho10.object_id
    AND hcd.dim12 = ho12.object_id
    AND hcd.dim13 = ho13.object_id
    AND hcd.dim15 = ho15.object_id
    AND hcd.dim16 = ho16.object_id
    AND hcd.dim17 = ho17.object_id
    and HO5.OBJECT_NAME = 'Working'
    --and hcdi.generation != 0
    --and hcdi.label like 'JRTEST-%'
    --and hcd.detail_id = 253102
    /*GROUP BY HCD.Dim1, HCD.Dim2, HCD.Dim3, HCD.Dim4,
    HCD.Dim5,
    HCD.Dim6,
    HCD.Dim7,
    HCD.Dim8,
    HCD.Dim10,
    HCD.Dim12,
    HCD.Dim13,
    HCD.Dim15,
    HCD.Dim16,
    HCD.Dim17*/;
    CURSOR BUDGET_DETAILS_CU(
    /*scenario_p in varchar2,
    account_p in varchar2,
    entity_p in varchar2,
    month_p in varchar2,
    version_p in varchar2,
    currency_p in varchar2,
    year_p in varchar2,
    project_p in varchar2,
    cc_p in varchar2,
    grplcl_p in varchar2,
    product_p in varchar2,
    salesregion_p in varchar2,
    contractanalysis_p in varchar2,
    ic_p in varchar2*/
    detail_id_p in number
    IS
    SELECT
    /* HO1.OBJECT_NAME SCENARIO,
    HO2.OBJECT_NAME ACCOUNT,
    HO3.OBJECT_NAME ENTITY,
    HO4.OBJECT_NAME Month,
    HO5.OBJECT_NAME Version,
    HO6.OBJECT_NAME Currency,
    HO7.OBJECT_NAME Year,
    HO8.OBJECT_NAME Project,
    HO10.OBJECT_NAME CC,
    HO12.OBJECT_NAME Grplcl,
    HO13.OBJECT_NAME Product,
    HO15.OBJECT_NAME SalesRegion,
    HO16.OBJECT_NAME ContractAnalysis,
    HO17.OBJECT_NAME IC, */
    label,
    NVL(HCDI.VALUE,0) AMOUNT,
    HCDI.Position,
    HCDI.operator,
    HCDI.generation
    FROM /*hsp_column_detail HCD,*/
    hsp_column_detail_ITEM HCDI
    /* HSP_OBJECT HO1,
    HSP_OBJECT HO2,
    HSP_OBJECT HO3,
    HSP_OBJECT HO4,
    HSP_OBJECT HO5,
    HSP_OBJECT HO6,
    HSP_OBJECT HO7,
    HSP_OBJECT HO8,
    HSP_OBJECT HO10,
    HSP_OBJECT HO12,
    HSP_OBJECT HO13,
    HSP_OBJECT HO15,
    HSP_OBJECT HO16,
    HSP_OBJECT HO17*/
    --WHERE hcd.detail_id = hcdi.detail_id
    WHERE hcdi.detail_id = detail_id_p
    /*AND hcd.dim1 = ho1.object_id
    AND hcd.dim2 = ho2.object_id
    AND hcd.dim3 = ho3.object_id
    AND hcd.dim4 = ho4.object_id
    AND hcd.dim5 = ho5.object_id
    AND hcd.dim6 = ho6.object_id
    AND hcd.dim7 = ho7.object_id
    AND hcd.dim8 = ho8.object_id
    AND hcd.dim10 = ho10.object_id
    AND hcd.dim12 = ho12.object_id
    AND hcd.dim13 = ho13.object_id
    AND hcd.dim15 = ho15.object_id
    AND hcd.dim16 = ho16.object_id
    AND hcd.dim17 = ho17.object_id*/
    --and hcdi.generation != 0
    --and label like 'JRTEST-%'
    /*AND HCD.Dim1 = scenario_p
    AND HCD.Dim2 = account_p
    AND HCD.Dim3 = entity_p
    AND HCD.Dim4 = month_p
    AND HCD.Dim5 = version_p
    AND HCD.Dim6 = currency_p
    AND HCD.Dim7 = year_p
    AND HCD.Dim8 = project_p
    AND HCD.Dim10 = cc_p
    AND HCD.Dim12 = grplcl_p
    AND HCD.Dim13 = product_p
    AND HCD.Dim15 = salesregion_p
    AND HCD.Dim16 = contractanalysis_p
    AND HCD.Dim17 = ic_p*/
    ORDER BY hcdi.position;
    -- Variable Declaration
    running_total_ln number :=0;
    prev_running_total_ln number :=0;
    add_amount number :=0;
    multiply_amount number :=1;
    prev_generation number :=0;
    prev_add_amount number :=0;
    prev_multiply_amount number :=1;
    running_total_gen0 number :=0;
    running_gen0_op number :=0;
    running_total_gen1 number :=0;
    running_gen1_op number :=0;
    running_total_gen2 number :=0;
    running_gen2_op number :=0;
    running_total_gen3 number :=0;
    running_gen3_op number :=0;
    running_total_gen4 number :=0;
    running_gen4_op number :=0;
    running_total_gen5 number :=0;
    running_gen5_op number :=0;
    output_file utl_file.file_type;
    -- Begin PL/SQL processing
    BEGIN
    --DBMS_OUTPUT.
    DBMS_OUTPUT.ENABLE(1000000);
    DBMS_OUTPUT.PUT_LINE('Begin Processing');
    output_file := utl_file.fopen ('C:\temp', 'test.txt', 'W');
    -- Begin Header For Loop
    FOR BUDGET_HEADERS_CV IN BUDGET_HEADERS_CU
    LOOP
    --Reset Running Totals
    running_total_ln:=0;
    prev_running_total_ln:=0;
    add_amount:=0;
    multiply_amount:=1;
    prev_generation:=0;
    prev_add_amount:=0;
    prev_multiply_amount:=1;
    running_total_gen0:=0;
    running_gen0_op:=0;
    running_total_gen1:=0;
    running_gen1_op:=0;
    running_total_gen2:=0;
    running_gen2_op:=0;
    running_total_gen3:=0;
    running_gen3_op:=0;
    running_total_gen4:=0;
    running_gen4_op:=0;
    running_total_gen5:=0;
    running_gen5_op:=0;
    -- Begin Detail For Loop
    FOR BUDGET_DETAILS_CV IN BUDGET_DETAILS_CU(
    BUDGET_HEADERS_CV.Detail_ID
    /*BUDGET_HEADERS_CV.SCENARIO_ID,
    BUDGET_HEADERS_CV.ACCOUNT_ID,
    BUDGET_HEADERS_CV.ENTITY_ID,
    BUDGET_HEADERS_CV.Month_ID,
    BUDGET_HEADERS_CV.Version_ID,
    BUDGET_HEADERS_CV.Currency_ID,
    BUDGET_HEADERS_CV.Year_ID,
    BUDGET_HEADERS_CV.Project_ID,
    BUDGET_HEADERS_CV.CC_ID,
    BUDGET_HEADERS_CV.Grplcl_ID,
    BUDGET_HEADERS_CV.Product_ID,
    BUDGET_HEADERS_CV.SalesRegion_ID,
    BUDGET_HEADERS_CV.ContractAnalysis_ID,
    BUDGET_HEADERS_CV.IC_ID*/
    LOOP
    -- Null;
    add_amount :=0;
    multiply_amount :=1;
    IF BUDGET_DETAILS_CV.OPERATOR = 1 THEN
    add_amount := BUDGET_DETAILS_CV.Amount;
    End if;
    IF BUDGET_DETAILS_CV.OPERATOR = 2 THEN
    add_amount := BUDGET_DETAILS_CV.Amount * -1;
    End if;
    IF BUDGET_DETAILS_CV.OPERATOR = 3 THEN
    multiply_amount := BUDGET_DETAILS_CV.Amount;
    End if;
    IF BUDGET_DETAILS_CV.OPERATOR = 4 THEN
    multiply_amount := 1/BUDGET_DETAILS_CV.Amount;
    End if;
    IF BUDGET_DETAILS_CV.Position = 0 then
    running_total_gen0 := add_amount*multiply_amount;-- we are dealing with the first line
    Else
    if BUDGET_DETAILS_CV.GENERATION = prev_generation then
    -- run whatever total we are on up
    if BUDGET_DETAILS_CV.GENERATION = 0 then
    running_total_gen0 := (running_total_gen0 + add_amount)*multiply_amount;
    end if;
    if BUDGET_DETAILS_CV.GENERATION = 1 then
    running_total_gen1 := (running_total_gen1 + add_amount)*multiply_amount;
    end if;
    if BUDGET_DETAILS_CV.GENERATION = 2 then
    running_total_gen2 := (running_total_gen2 + add_amount)*multiply_amount;
    end if;
    if BUDGET_DETAILS_CV.GENERATION = 3 then
    running_total_gen3 := (running_total_gen3 + add_amount)*multiply_amount;
    end if;
    end if;
    if BUDGET_DETAILS_CV.GENERATION = prev_generation +1 then
    -- we are going up a generation
    -- (we cannot go up to gen0
    if BUDGET_DETAILS_CV.GENERATION = 1 then
    running_total_gen1:=0;-- reset gen1 counter
    running_gen0_op:=BUDGET_DETAILS_CV.OPERATOR; -- Store the sign for later operation
    running_total_gen0 := running_total_gen0/prev_multiply_amount - prev_add_amount; -- Remove parent from Gen 0 total
    running_total_gen1 := (running_total_gen1 + add_amount)*multiply_amount;
    end if;
    if BUDGET_DETAILS_CV.GENERATION = 2 then
    running_total_gen2:=0;-- reset gen1 counter
    running_gen1_op:=BUDGET_DETAILS_CV.OPERATOR; -- Store the sign for later operation
    running_total_gen1 := running_total_gen1/prev_multiply_amount - prev_add_amount; -- Remove parent from Gen 1 total
    running_total_gen2 := (running_total_gen2 + add_amount)*multiply_amount;
    end if;
    if BUDGET_DETAILS_CV.GENERATION = 3 then
    running_total_gen3:=0;-- reset gen1 counter
    running_gen2_op:=BUDGET_DETAILS_CV.OPERATOR; -- Store the sign for later operation
    running_total_gen2 := running_total_gen2/prev_multiply_amount - prev_add_amount; -- Remove parent from Gen 2 total
    running_total_gen3 := (running_total_gen3 + add_amount)*multiply_amount;
    end if;
    end if;
    if BUDGET_DETAILS_CV.GENERATION = prev_generation - 1 then
    -- we are Down a generation
    if BUDGET_DETAILS_CV.GENERATION = 0 then
    --we need to "add" back the previous gen 1 parent
    IF running_gen0_op = 1 THEN
    running_total_gen0 := running_total_gen0 + running_total_gen1;
    End if;
    IF running_gen0_op = 2 THEN
    running_total_gen0 := running_total_gen0 - running_total_gen1;
    End if;
    IF running_gen0_op = 3 THEN
    running_total_gen0 := running_total_gen0 * running_total_gen1;
    End if;
    IF running_gen0_op = 4 THEN
    running_total_gen0 := running_total_gen0 / running_total_gen1;
    End if;
    -- we need to add the current member to the gen0
    running_total_gen0 := (running_total_gen0 + add_amount)*multiply_amount;
    END IF;
    if BUDGET_DETAILS_CV.GENERATION = 1 then
    --we need to "add" back the previous gen 2 parent
    IF running_gen1_op = 1 THEN
    running_total_gen1 := running_total_gen1 + running_total_gen2;
    End if;
    IF running_gen1_op = 2 THEN
    running_total_gen1 := running_total_gen1 - running_total_gen2;
    End if;
    IF running_gen1_op = 3 THEN
    running_total_gen1 := running_total_gen1 * running_total_gen2;
    End if;
    IF running_gen1_op = 4 THEN
    running_total_gen1 := running_total_gen1 / running_total_gen2;
    End if;
    -- we need to add the current member to the gen1
    running_total_gen1 := (running_total_gen1 + add_amount)*multiply_amount;
    end if;
    if BUDGET_DETAILS_CV.GENERATION = 2 then
    --we need to "add" back the previous gen 3 parent
    IF running_gen1_op = 1 THEN
    running_total_gen2 := running_total_gen2 + running_total_gen3;
    End if;
    IF running_gen1_op = 2 THEN
    running_total_gen2 := running_total_gen2 - running_total_gen3;
    End if;
    IF running_gen1_op = 3 THEN
    running_total_gen2 := running_total_gen2 * running_total_gen3;
    End if;
    IF running_gen1_op = 4 THEN
    running_total_gen2 := running_total_gen2 / running_total_gen3;
    End if;
    -- we need to add the current member to the gen2
    running_total_gen2 := (running_total_gen2 + add_amount)*multiply_amount;
    end if;
    end if;
    if BUDGET_DETAILS_CV.GENERATION = prev_generation - 2 then
    -- we are Down 2 generations
    if BUDGET_DETAILS_CV.GENERATION = 0 then
    --we need to "add" back the previous gen 2 parent
    IF running_gen1_op = 1 THEN
    running_total_gen1 := running_total_gen1 + running_total_gen2;
    End if;
    IF running_gen1_op = 2 THEN
    running_total_gen1 := running_total_gen1 - running_total_gen2;
    End if;
    IF running_gen1_op = 3 THEN
    running_total_gen1 := running_total_gen1 * running_total_gen2;
    End if;
    IF running_gen1_op = 4 THEN
    running_total_gen1 := running_total_gen1 / running_total_gen2;
    End if;
    --we need to "add" back the previous gen 1 parent
    IF running_gen0_op = 1 THEN
    running_total_gen0 := running_total_gen0 + running_total_gen1;
    End if;
    IF running_gen0_op = 2 THEN
    running_total_gen0 := running_total_gen0 - running_total_gen1;
    End if;
    IF running_gen0_op = 3 THEN
    running_total_gen0 := running_total_gen0 * running_total_gen1;
    End if;
    IF running_gen0_op = 4 THEN
    running_total_gen0 := running_total_gen0 / running_total_gen1;
    End if;
    -- we need to add the current member to the gen0
    running_total_gen0 := (running_total_gen0 + add_amount)*multiply_amount;
    END IF;
    if BUDGET_DETAILS_CV.GENERATION = 1 then
    --we need to "add" back the previous gen 3 parent
    IF running_gen1_op = 1 THEN
    running_total_gen2 := running_total_gen2 + running_total_gen3;
    End if;
    IF running_gen1_op = 2 THEN
    running_total_gen2 := running_total_gen2 - running_total_gen3;
    End if;
    IF running_gen1_op = 3 THEN
    running_total_gen2 := running_total_gen2 * running_total_gen3;
    End if;
    IF running_gen1_op = 4 THEN
    running_total_gen2 := running_total_gen2 / running_total_gen3;
    End if;
    --we need to "add" back the previous gen 2 parent
    IF running_gen1_op = 1 THEN
    running_total_gen1 := running_total_gen1 + running_total_gen2;
    End if;
    IF running_gen1_op = 2 THEN
    running_total_gen1 := running_total_gen1 - running_total_gen2;
    End if;
    IF running_gen1_op = 3 THEN
    running_total_gen1 := running_total_gen1 * running_total_gen2;
    End if;
    IF running_gen1_op = 4 THEN
    running_total_gen1 := running_total_gen1 / running_total_gen2;
    End if;
    -- we need to add the current member to the gen1
    running_total_gen1 := (running_total_gen1 + add_amount)*multiply_amount;
    END IF;
    if BUDGET_DETAILS_CV.GENERATION = prev_generation - 3 then
    -- we are Down 3 generations
    if BUDGET_DETAILS_CV.GENERATION = 0 then
    --we need to "add" back the previous gen 3 parent
    IF running_gen1_op = 1 THEN
    running_total_gen2 := running_total_gen2 + running_total_gen3;
    End if;
    IF running_gen1_op = 2 THEN
    running_total_gen2 := running_total_gen2 - running_total_gen3;
    End if;
    IF running_gen1_op = 3 THEN
    running_total_gen2 := running_total_gen2 * running_total_gen3;
    End if;
    IF running_gen1_op = 4 THEN
    running_total_gen2 := running_total_gen2 / running_total_gen3;
    End if;
    --we need to "add" back the previous gen 2 parent
    IF running_gen1_op = 1 THEN
    running_total_gen1 := running_total_gen1 + running_total_gen2;
    End if;
    IF running_gen1_op = 2 THEN
    running_total_gen1 := running_total_gen1 - running_total_gen2;
    End if;
    IF running_gen1_op = 3 THEN
    running_total_gen1 := running_total_gen1 * running_total_gen2;
    End if;
    IF running_gen1_op = 4 THEN
    running_total_gen1 := running_total_gen1 / running_total_gen2;
    End if;
    --we need to "add" back the previous gen 1 parent
    IF running_gen0_op = 1 THEN
    running_total_gen0 := running_total_gen0 + running_total_gen1;
    End if;
    IF running_gen0_op = 2 THEN
    running_total_gen0 := running_total_gen0 - running_total_gen1;
    End if;
    IF running_gen0_op = 3 THEN
    running_total_gen0 := running_total_gen0 * running_total_gen1;
    End if;
    IF running_gen0_op = 4 THEN
    running_total_gen0 := running_total_gen0 / running_total_gen1;
    End if;
    -- we need to add the current member to the gen0
    running_total_gen0 := (running_total_gen0 + add_amount)*multiply_amount;
    END IF;
    end if;
    END IF;
    End IF;
    END LOOP; -- End of Detail Loop
    --DBMS_OUTPUT.PUT_LINE(BUDGET_HEADERS_CV.SCENARIO||';'||BUDGET_HEADERS_CV.ACCOUNT||';'||BUDGET_HEADERS_CV.ENTITY||';'||BUDGET_HEADERS_CV.Month||';'||BUDGET_HEADERS_CV.Version||';'||BUDGET_HEADERS_CV.Currency||';'||BUDGET_HEADERS_CV.Year||';'||BUDGET_HEADERS_CV.Project||';'||BUDGET_HEADERS_CV.CC||';'||BUDGET_HEADERS_CV.Grplcl||';'||BUDGET_HEADERS_CV.Product||';'||BUDGET_HEADERS_CV.SalesRegion||';'||BUDGET_HEADERS_CV.ContractAnalysis||';'||BUDGET_HEADERS_CV.IC||';'||running_total_gen0);
    utl_file.put_line(output_file,BUDGET_HEADERS_CV.SCENARIO||';'||BUDGET_HEADERS_CV.ACCOUNT||';'||BUDGET_HEADERS_CV.ENTITY||';'||BUDGET_HEADERS_CV.Month||';'||BUDGET_HEADERS_CV.Version||';'||BUDGET_HEADERS_CV.Currency||';'||BUDGET_HEADERS_CV.Year||';'||BUDGET_HEADERS_CV.Project||';'||BUDGET_HEADERS_CV.CC||';'||BUDGET_HEADERS_CV.Grplcl||';'||BUDGET_HEADERS_CV.Product||';'||BUDGET_HEADERS_CV.SalesRegion||';'||BUDGET_HEADERS_CV.ContractAnalysis||';'||BUDGET_HEADERS_CV.IC||';'||running_total_gen0);
    /*BUDGET_HEADERS_CV.SCENARIO, BUDGET_HEADERS_CV.ACCOUNT, BUDGET_HEADERS_CV.ENTITY, BUDGET_HEADERS_CV.Month, BUDGET_HEADERS_CV.Version,BUDGET_HEADERS_CV.Currency, BUDGET_HEADERS_CV.Year, BUDGET_HEADERS_CV.Project, BUDGET_HEADERS_CV.CC, BUDGET_HEADERS_CV.Grplcl, BUDGET_HEADERS_CV.Product, BUDGET_HEADERS_CV.SalesRegion, BUDGET_HEADERS_CV.ContractAnalysis, BUDGET_HEADERS_CV.IC */
    END LOOP; -- End of Header Loop
    --DBMS_OUTPUT.PUT_LINE('Total');
    -- DBMS_OUTPUT.PUT_LINE('End Processing');
    utl_file.fclose(output_file);
    END;
    Edited by: JeremieR on Apr 18, 2011 5:02 AM

  • Query That Retrieves New Customers & Leads By Date

    Hello All --
    We would like to create a Query that retrieves new customers and leads based on the date (or date range) they are entered into SAP. 
    Can we create a UDF named STDATE --- Start Date -- and have a Query that allows us to select based on this date range?
    Start dates are entered in this format --- YYYYMMDD.
    Then, the Query would pull out:
    Contact...Company...Bill To Address...Bill To City...Bill To State....Bill To Zip...Phone...Email
    Is this possible to do?
    Thanks!
    Mike

    Hi Mike ,
    You can add some other field as you like .This report will give you combination of both customer and lead .
    I couldn't understand the purpose ,but I like previous query as i have flexibilty to choose customer or vendor .
    SELECT T0.[CreateDate], T0.[CntctPrsn], T0.[CardName], T0.[Address], T0.[City], T0.[E_Mail], T0.[ZipCode], T0.[Phone1] FROM OCRD T0 WHERE T0.[CardType] in ('C','L') and T0.[CreateDate]=[%0]
    If you agree with me ,you can use this query
    SELECT T0.[CreateDate], T0.[CntctPrsn], T0.[CardName], T0.[Address], T0.[City], T0.[E_Mail], T0.[ZipCode], T0.[Phone1] FROM OCRD T0 WHERE T0.[CardType] =[%0] or T0.[Cardtype]=[%1] and
    T0.[CreateDate]=[%2]
    Regarding the date issue , since you are entering paramenter it will match with the date you are looking for .If you have more than one customer created on same day , you willreceive multiple client .
    Thank you
    Bishal

  • Query to retrieve previous working day?

    I need to write a query that will retrieve the previous working day. Therefore, it must exclude weekends and holidays.
    For example, the previous working day for Saturday, February 19 or Sunday, February 20 would be Friday, February 18. And since Monday, February 21 was a holiday for us then the previous working day would also be Friday, February 18.
    I've found some queries that allow me to find the previous working day excluding weekends, but I'm having difficulty with the holidays aspect. We have a table called CORPHOLIDAY that contains a field HOLIDAY that stores the holiday dates.
    Can I do this with a simple query? I'm not proficient with Oracle, so any and all help is appreciated. Thanks!

    Welcome to the forum!
    As Dan said, whenever you have a question, it really helps if you post CREATE TABLE and INSERT statements to create whatever tables you need, so people can re-create the problem and test their ideas. Also post the results you want from that data, and your version of Oracle.
    The sample data might be as simple as this:
    CREATE TABLE     corpholiday
    (     holiday     DATE
    INSERT INTO corpholiday (holiday) VALUES (DATE '2011-02-21');Here's one way to get the results you want. You enter a starting date (such as February 22, 2011) and the query produces the last working day before that date (in this case, February 18).
    WITH     consecutive_days     AS
         SELECT     TO_DATE ( '22-Feb-2011'     -- Input parameter
                   , 'DD-Mon-YYYY'
                   ) - LEVEL     AS a_date
         FROM     dual
         CONNECT BY     LEVEL     <= 4     -- 1 + Max. possible non-work days
    SELECT     MAX (a_date)     AS prev_work_day
    FROM           consecutive_days     c
    LEFT OUTER JOIN      corpholiday          h  ON     c.a_date     = h.holiday
    WHERE     TO_CHAR ( a_date
              , 'Dy'
              , 'NLS_DATE_LANGUAGE=ENGLISH'     -- If necessary
              )     NOT IN ('Sat', 'Sun')
    AND     h.holiday     IS NULL
    ;What you might really like for this job is a WHILE loop, something that would start at the given date, subtract one, test if that day was a work day, and, if necessary, repeat until it did find a work day. That's how you might do it in a procedural language, like PL/SQL, and that's exactly what a lot of people would do: write a PL/SQL function, that could us a WHILE loop. SQL is a non-procedural language, so it doesn't have anything like a loop. Using a CONNECT BY query, as shown above, we can simulate the behavior of a FOR loop, where we do a fixed number of iterations. The query above works by using CONNECT BY to generate the last 4 dates before the given starting date. What is that magic number 4? It's the worst case of how many consecutive days there can be (at least where I work) that is sure to have at least one work day. Where I work, holidays are always at least a week apart, so the longest you can go without a work day is like the example you gave: a Monday (or Friday) holiday, adjacent to the 2 weekend days. You may need to change the number 4 to something higher if, say, December 25 and 26 were both holidays, or if Good Friday and Easter Monday were both holidays.
    As posted, the query above works in Oracle 9 (and up), but it can be modified for earlier versions.
    Edited by: Frank Kulash on Feb 23, 2011 8:57 PM
    Added explanation

  • Query to retrieve the 'My Favorites' sub folder names from InfoView

    Please help me with the query which can get all the folder names present in 'My Favorites' in the InfoView, and also query to get all the folder names in 'Public Folders' for the current user?
    Thanks

    To get all the folders under Public Folders accessible by current user:
    1. Logon as that user.
    2. Run the query: select * from ci_infoobjects where si_kind='folder' and si_parentid=0; This only returns the top level folders. To get the subfolders within these folders, you need to make a recursive call changing si_parentid. Si_parentid=0 stands for root, change it with SI_ID of folder for which you are trying to find subfolders. To run the query and get results the user may need some access at the root level ( not granted for a general user by default, granted only for administrator)
    The folders or objects listed under My Favorites are contents of a user's favorite or personal folder and a user should have full access to it by default. To retrieve contents of that:
    select si_id from ci_infoobjects where si_kind='favoritesfolder' and si_name='<user name>' which will give a User's favorite folder and SI_ID of it.
    then call:
    Select * from ci_infoobjects where si_parentid=<SI_ID obtained from previous query>
    will list all the top level objects, folders in a user's favorite folder.

Maybe you are looking for

  • Adobe Premiere CC 2014.2: losing rendered files when using warp stabilizer

    Hi, I am constantly losing rendered files when using the warp stabilizer. So far I have tried about every hint I could find on the web such as cleaning the cache, rebuilding the rendered files, creating additional sequences etc etc. Honestly I am get

  • GW client crash ater 5 seconds, no display of e-mails

    Hello All; I have 1 user which crashes after 5 seconds after entering the users password. GW Client 7.04. The user can use GWWebaccess to view e-mails and the BES (4.17) reads the e-mails so the user can use a BB. Windows event ID of 1000 Faulting ap

  • 4s turn off suddenly while using

    my 4s will turn off suddenly while using ,and i have to hit home and power button same time to turn on the iphone.it happens every two days,and sometimes twice a day.is it a hardware problem?

  • Locking problem in BPS solution not getting solved  using RSPLSE. SEM_BPS_S

    Can anyone tell me exactly what "rsplse" offers to solve locking in BPS? We have made correct selection of characteristics (in our case "costcentre" infoobject) in tab "Lock characteristics" , but still when two people are trying to access (write) da

  • Settings for smaller sized videos in the DVD?

    I have a large project from which I should make one or maximum two DVDs. I have exported the timelines from PP CC using the preset for MPEG2 DVDs (quality 75%, 720x576, framerate 25, min bitrate 2.8, target 5.0 maximum 7.0) This makes the project too