SQL that provides direct and Indirect reports

SELECT DISTINCT J.EMPLID ,J.EMPL_RCD ,A.NAME ,J.BUSINESS_UNIT ,J.JOBCODE ,JC.DESCR ,J.DEPTID ,D.DESCR
,J.SUPERVISOR_ID ,J.REPORTS_TO ,J.LOCATION ,J.COMPANY ,J.PAYGROUP ,J.GP_PAYGROUP ,ED.WORKGROUP ,ED.TASKGROUP
,J.POSITION_NBR ,L.BUILDING, WG.INCL_ML_BRK_FLG
FROM PS_JOBCODE_TBL JC , PS_JOB J , PS_TL_EMPL_DATA ED, PS_TL_GROUP_DTL F ,PS_TL_GRP_SECURITY S
,PS_PERSON_NAME A , PS_DEPT_TBL D, PS_LOCATION_TBL L, PS_TL_WRKGRP_TBL WG
WHERE S.GROUP_ID = F.GROUP_ID
AND F.EMPLID = J.EMPLID
AND F.EMPL_RCD = J.EMPL_RCD
AND F.EMPLID = A.EMPLID
AND F.EMPLID = ED.EMPLID
AND F.EMPL_RCD = ED.EMPL_RCD
AND S.ROWSECCLASS = 'DPALL'
AND J.EFFDT = ( SELECT MAX(J1.EFFDT) FROM PS_JOB J1
WHERE J1.EMPLID = J.EMPLID
AND J1.EMPL_RCD = J.EMPL_RCD
AND J1.EFFDT <= '22-MAY-2012')
AND J.EFFSEQ = ( SELECT MAX(J2.EFFSEQ) FROM PS_JOB J2
WHERE J2.EMPLID = J.EMPLID
AND J2.EMPL_RCD = J.EMPL_RCD
AND J2.EFFDT = J.EFFDT )
AND ED.EFFDT = ( SELECT MAX(ED1.EFFDT) FROM PS_TL_EMPL_DATA ED1
WHERE ED1.EMPLID = ED.EMPLID
AND ED1.EMPL_RCD = ED.EMPL_RCD
AND ED1.EFFDT <= '22-MAY-2012')
AND JC.SETID = J.SETID_JOBCODE
AND JC.JOBCODE = J.JOBCODE
AND JC.EFFDT = ( SELECT MAX(JC1.EFFDT) FROM PS_JOBCODE_TBL JC1
WHERE JC1.SETID = J.SETID_JOBCODE
AND JC1.JOBCODE = J.JOBCODE
AND JC1.EFFDT <= '22-MAY-2012')
AND D.SETID = J.SETID_DEPT
AND D.DEPTID = J.DEPTID
AND D.EFFDT = ( SELECT MAX(D1.EFFDT) FROM PS_DEPT_TBL D1
WHERE D1.SETID = J.SETID_DEPT
AND D1.DEPTID = J.DEPTID
AND D1.EFFDT <= '22-MAY-2012')
AND L.SETID = J.SETID_LOCATION
AND L.LOCATION = J.LOCATION
AND L.EFFDT = ( SELECT MAX(EFFDT) FROM PS_LOCATION_TBL
WHERE SETID = L.SETID
AND LOCATION = L.LOCATION
AND EFFDT <= '22-MAY-2012')
AND J.SUPERVISOR_ID LIKE '76634%'
AND A.EMPLID <> '76634'
AND ED.WORKGROUP = WG.WORKGROUP
AND WG.EFFDT = (SELECT MAX(WG1.EFFDT) FROM PS_TL_WRKGRP_TBL WG1
WHERE WG.WORKGROUP = WG1.WORKGROUP
AND WG1.EFFDT <= '22-MAY-2012'
AND J.EMPL_STATUS IN ('A','L','P','S')
AND J.EFFDT <= '20-MAY-2012');
Above SQL provides me the list of employees (only direct reports) who report to EMPLID 76634. Now I want to modify this SQL so that It will also provide me the list of employees from a lower level (indirect reports).
For example, if employees 1, 2 report to 76634. And 3,4 report to 1. And 5,6 report to 2. I want to modify the above SQL such that it will retrieve both direct and indirect reports for 76634 i.e 1,2,3,4,5 and 6.
As of now above SQL will retrieve only 1,2. Any thoughts?

SQLServer uses a recursive query for this.
Just typing "SQLServer recursive query" in a search engine will provide you with tons of examples, but I will redirect you to the source MSDN,
http://msdn.microsoft.com/en-us/library/ms175972%28SQL.90%29.aspx
Look for the following example
D. Using a recursive common table expression to display multiple levels of recursion
The following example shows the hierarchical list of managers and the employees who report to them.
USE AdventureWorks;
GO
WITH DirectReports(ManagerID, EmployeeID, EmployeeLevel) AS
SELECT ManagerID, EmployeeID, 0 AS EmployeeLevel
FROM HumanResources.Employee
WHERE ManagerID IS NULL
UNION ALL
SELECT e.ManagerID, e.EmployeeID, EmployeeLevel + 1
FROM HumanResources.Employee e
INNER JOIN DirectReports d
ON e.ManagerID = d.EmployeeID
SELECT ManagerID, EmployeeID, EmployeeLevel
FROM DirectReports ;
GO

Similar Messages

  • Calculating DIrect and indirect reports for managers

    Hi,
    I have a flattened manager hierarchy. I want to calculate the direct and indirect reports for every manager. how can i do this.
    Thanks
    Edited by: user599926 on Apr 18, 2010 4:01 PM

    I've never worked with Access as a database, before.  But, if this were SQL (and it might work), then, yes, a LEFT OUTER JOIN would do the trick.
    SELECT ta.Lastname, ta.Firstname, ta.EmpID, ta.MgrEmpID, ta.Email, ta.Location
    FROM TableA ta LEFT OUTER JOIN TableA tb ON tb.MgrEmpID = ta.EmpID
    ORDER BY ta.Lastname, ta.Firstname, tb.Lastname, tb.FIrstname
    Or something like that.
    ^_^

  • Direct and Indirect

    Hi:
    can someone tell me whats the difference between direct and Indirect reports in SRM-BW.
    whats the functionality of them.
    how to figure out them
    where to find them, any T-codes, tables will of great help.
    it would be great if some one can tell the relation between R/3 PO and a SRM PO
    Thanks
    kedar

    Hi,
    If I understood Your question about direct and indirect reporting in SRM-BW.
    Direct reporting it is a SAP RemoteCube in BW. RemoteCube is and InfoProvider. This is a special RemoteCube that allows You to define queries with direct access to transaction data in other SAP systems. RemoteCubes are defined on the basis on an InfoSource with flexible updating, and assume the characteriscics and key figures of the InfoSource.
    Indirect reporting is like standard BW reporting with master data, transactional data, attributes and hierarchies.
    All BI content You may find in transaction RSA6 on SRM side.
    There is not many difference between SRM and R/3 PO's. On both side you may create PO from SC, PO with direct or indirect material etc.
    Please look into service.sap.com/instguides -> SRM -> Plan-Driven Procurement and Self-Service Procurement
    Regards,
    Marcin

  • Getting direct reporting and indirect reporting employee

    Hi,
    In one of my development, their is a requirement to have a screen of type Tcode PPMDT.
    My screen will be having tab strip for direct and indirect employee and on both tabs org structure will be displayed.
    I am using function module RH_STRUC_GET to get the org structure details. I need to know the logic of separating direct reporting employee from indirect reporting employee from the data returned from function module.
    Thanks
    Vishal Kapoor

    Hi,
    In one of my development, their is a requirement to have a screen of type Tcode PPMDT.
    My screen will be having tab strip for direct and indirect employee and on both tabs org structure will be displayed.
    I am using function module RH_STRUC_GET to get the org structure details. I need to know the logic of separating direct reporting employee from indirect reporting employee from the data returned from function module.
    Thanks
    Vishal Kapoor

  • Finding direct and indirect dependency

    Hi,
    I have table say SAPECC, which is used in one of the procedure as given below :
    create or procedure test121
    as
    begin
    insert into sapecc2
    select * from sapecc;
    end;
    And SAPECC2 is used in another procedure as given below :
    create or procedure test122
    as
    begin
    insert into sapecc3
    select * from sapecc2;
    end;
    Now if I want to get what are the direct and indirect dependency for SAPECC, how can we get that? Say I want to see TEST121 procedure and SAPECC2 table are the 1st level dependency for SAPECC and TEST122 procedure and SAPECC3 table are the 2st level dependency for SAPECC.
    Regards,
    Koushik

    Hi Koushik,
    There are no dependencies as you describe them between the sapeccX tables.
    SQL> select level
              ,name
              ,type
              ,referenced_name
              ,referenced_type
          from user_dependencies
    start with referenced_name like 'SAPECC%'
    connect by prior referenced_name = name
    LEVEL NAME         TYPE         REFERENCED_N REFERENCED_T
        1 TEST121      PROCEDURE    SAPECC       TABLE      
        1 TEST121      PROCEDURE    SAPECC2      TABLE      
        1 TEST122      PROCEDURE    SAPECC2      TABLE      
        1 TEST122      PROCEDURE    SAPECC3      TABLE      
    4 rows selected.I don't know about 11g and PL/Scope maybe you can get something from there.
    As a final resort you can play with user_source:
    select *
      from user_source
    where name like 'TEST%';Regards
    Peter

  • Which Function Module can find all direct and indirect subordinate.

    Hi,
        I have a employee number(Chief of a organizational unit A). Do you know which function module can get all the direct and indirect subordinate of this chief? Indirect subordinate means that this chief can also view the Organizational unit(for example, Org. unit B) that under Org. Unit A. Further more, this chief can also view all the employees in other org unit that under Org. Unit B. If there is no such function module, do anyone of you have the example coding to get it? Your help is greatly appreciated. Thanks.

    use RH_STRUC_GET
    ~Suresh

  • How to find both direct and indirect responsibilites attached to user

    Hi All,
    I have a requirement to write a sql to list all direct and indirect responsibilities attached to a particular user.
    Please help me.
    Thanks,
    Raghav.

    Hi;
    Pelase see below which could be helpful for your issue:
    responsibilty -to find any users assigned
    to find any users assigned to a responsibilty
    Regard
    Helios

  • What r the direct and indirect taxes

    hi gurus,
    can any one pls give me what r the direct and indirect taxes.
    Thanks in advance,
    RAVI
    Moderator: Please, respect SDN rules. As it's not your first warning, upon next violation your user will be banned

    Hi,
    the Tax tht we Pay directly to Govt is Direct tax and tax tht we pay indirectly is Indirect tax. Ex. Income tax on  salaries is direct tax and Sales Tax on Products is a indirect Tax.
    Hope you got clarify on the Both type of Taxes.
    Thanks
    Goutam
    Edited by: Goutam78 on May 27, 2011 3:07 PM

  • Help on Direct and Indirect Exchange Rate formula

    Dear Experts,
    As per subject, can anyone write the formula of how both "direct" and "indirect" exchange rate calculation works in SAP B1?
    Warmest Regards,
    Chinho

    Hi Chinho,
    Direct: X units of local currency (LC) = 1 unit of foreign currency (FC)
    Indirect: 1 unit of LC = X units of FC
    Therefore, considert his example:
    LC = EUR
    FC = GBP
    GBP Rate is set as 1.23
    Document total = GBP 10.00
    GBP 10.00 = EUR 12.30 when using the 'Direct Method' (1.23 EUR = 1 GBP)
    GBP 10.00 = EUR 8.13 when using the 'Indirect Method' (1 EUR = 1.23 GBP)
    All the best,
    Kerstin

  • Report for consumption for direct and indirect

    Can any body reply for if any consumption report is available for following requirement(1+2).
    1) Matl recd and issued to Prod order.
    2) Matl recd and at GR itself consumed for production (PO with acc assignment).
    so is there any report that will give me consumption report for the material for combination of above two.
    Regards,
    SDN Browser
    Edited by: Sdn Browser on Jan 12, 2010 7:15 AM

    Hi
    hi,
    go to MB51 and enter the movent types shown below for issues or consumption, then you will get list of all documents related to consuptions.
    201-consumption for cost centrer
    221-consumption for project
    231-consumption for sales order
    241-consumption for assest
    251-consumption for sales
    261-consumption for order
    281-consumption for network
    291-consumption for all account assignments.
    Vipin

  • Differentiating Direct and Indirect Spend

    Dear All,
    There is a requirement where all the data from ECC is being brought in SPM. This consists of direct spend as well as indirect spend (services, consulting, other sundry expenses). Is there a way we can use some indicator which can be used to identify the direct/indirect spend?
    The intention is to compare Direct vs Indirect spend and generate reports based on this.
    Are there any best practices to implement this?
    Thanks in advance,
    Regards, Ankur

    SAP doesnt provide any indicator to differentiate Direct vs. Indirect, understandably as the business needs to differentiate it. Usually your type of spend is differentiated at the material group (Category) level or material level. There are a dozen ways to skin a cat in SAP. You can create a mapping table based on category and material as applicable and have a indicator to represent the spend type and you can look up this table while extraction (data extraction kit) and fill it in a SAP provided field or a Z field. Or enhance your standard mara or material group to include a field to differentiate and enhance your extractor to map to the newly added fields.

  • Direct and Indirect Rates

    Hi Guru's,
    Can i know the difficulties in switching from direct to indirect rates.
    Currently in SAP we are inputting direct rates (eg .89694) for the conversion from USD to CAD.  This is causing FX issues when it comes to interco invoice processing as well as completing the Management report.  I would like SAP to switch to using the indirect rate (eg 1.1149). 
    Thanks for your help and will assign good points.
    Thanks

    Well, I have this wonderful SAP-documentation:
         All R/3 applications and functions process exchange rates using the direct quotation as well as the indirect quotation. Whether the exchange rate is defined or communicated using the direct or indirect method of quotation depends on the market standard or the individual business transaction. The use of indirect quotation is neither application nor country-specific - it affects all the components in which exchange rates are used.
         The direct quotation is also known as the price notation: The currency value is expressed in the local currency per unit of foreign currency. The indirect quotation is also known as the volume notation: The currency value is expressed in units of the foreign currency per unit of the local currency. Example:
         local currency: EUR, foreign currency: USD
         direct quotation: 1 USD = 0.92000EUR
    One unit of foreign currency USD costs the displayed number of units of local currency
         indirect quotation: 1 EUR = 1.08696 USD
    For one unit of the local currency EUR you will receive the displayed number of units of the foreign currency.
         For each currency pair you can define either the direct quotation or the indirect quotation as the standard notation for the exchange rate. If the exchange rate you enter does not have the same quotation as the standard quotation set up here, the exchange rate is highlighted to show this.
    From a mathematical point of view, it does not make any difference, you only need to be consistent. You cannot have one exchange rate as direct, another one as indirect quote. This will lead to hilarious figures in documents where you have items in local and different foreign currencies.
    The numerical issue is that you may gain more reliability for certain rates where you will lose a significant digit depending on direct/indirect. It was quite different to do a direct quote of the Italian Lira against the Euro as compared to the indirect quote. However, there are additional settings that help circumvent this problem.
    Hope this helps. Just remember: The main thing is to be consistent.
    Kind regards,
    Rudolf

  • Reporting on the SQL generated by webI and Deski reports

    I'm running BOXI 3.1 SP3 on a Windows.  I have about 2800 Webi and Deski reports live.  The majority of these reports return data from a Oracle data source that is not managed in-house. 
    I'm needing an admin type software that can query the repository for all my reports, generate the SQL for each report, spit out the name of the report and the SQL of the report and any filters/variables on the report into a searchable file that I can parse through to look for specific query filters (and report filters if it has any.) 
    I have method for pulling a list of reports that are using an universe's object X, but I really need a method of searching all the WHERE clauses all my reports and inside the report in the variables and
    Does anybody know of anything  that does this that is available for purchase?  I've tried leveraging the Activity Universe and it's just too slow to use.

    Hi,
    I am sorry but I could not infer much from your issue. However, vaguely I understand that you might have missed the grain settings for table A. Generally, when there are no proper grain settings (set through content tab in LTS), the BI Server might show NULL values.
    You may want to revisit your LTS for these tables once again and running through level 5 log also might help here.
    Hope this helps.
    Thank you,
    Dhar

  • How to get table and column names thats being used in SQL , that's generating all my reports on SSRS.

    Good day,
    I searched through the forum and cant find anything.
    I have around 300 published reports on SSRS and we are busy migrating to a new system.
    They have already setup their tables on the new system and I need to provide them with a list of table names and column names that are being used currently to generate the 300 reports on SSRS.
    We use various tables and databases to generate these reports, and will take me forever to go through each query to get this info.
    Is it at all possible to write a query in SQL 2008 that will give me all the table names and columns being used?
    Your assistance is greatly appreciated.
    I thank you.
    Andre.

    There's no straightforward method for that I guess. There are couple of things you can use to get these details
    1. query the ReportServer.dbo.Catalog table
    for getting details
    you may use script below for that
    http://gallery.technet.microsoft.com/scriptcenter/42440a6b-c5b1-4acc-9632-d608d1c40a5c
    2. Another method is to run the reports and run sql profiler trace on background to retrieve queries used.
    But in some of these cases the report might be using a procedure and you will get only procedure. Then its upto you to get the other details from procedure like tables used, columns etc
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Direct and indirect third party sales

    Hi gurus,
    please tell me what is direct third party sales and what is indirect third party sales?

    Hi,
    As far as my understanding
    Direct third party sales
    Meaning is that your vendor directly ship goods to your cutomer,here no delivery takeplace from your company
    Process :
    Sales order >> Purchase requisition >> P.O >> Invoice reciept from vendor >>> Invoice to customer woth refrance to sales order
    Indirect Third party sales
    Meaning is that here vendor ship material to your company and then from your company you ship to customer
    Process :
    Sales order >> Purchase requisition >> P.O >> Goods Reciepts >> Outbound delivery with refrance to order >> invoice with refrance to delivery
    Hope you understand
    Kapil

Maybe you are looking for