Selecting manager names for 20 levels

Hi,
Could you please help me on the following scenario?
Table "Base" holds the list of employee ids and names. Table "Mgr" holds the list of employee ids and their mgr ids (Who are also an employee) from level 1 to level 20. The requirement is to select the employee name with the 20 level mgr names (which can be obtained by referring the Base table).
For sample scenario, the following Creation Scripts add data for only 2 levels:
create table BASE
ENAME VARCHAR2(10),
EID NUMBER
insert into BASE (ENAME, EID)
values ('A', 1);
insert into BASE (ENAME, EID)
values ('B', 2);
insert into BASE (ENAME, EID)
values ('C', 3);
insert into BASE (ENAME, EID)
values ('D', 4);
insert into BASE (ENAME, EID)
values ('E', 5);
commit;
create table MGR
EID NUMBER,
MGRLVL1 NUMBER,
MGRLVL2 NUMBER
insert into MGR (EID, MGRLVL1, MGRLVL2)
values (1, 3, 4);
insert into MGR (EID, MGRLVL1, MGRLVL2)
values (2, 1, 5);
insert into MGR (EID, MGRLVL1, MGRLVL2)
values (3, 4, 2);
commit;
I tried to achieve the result using the following query:
select
m.eid,b1.ENAME,b2.ENAME lvlonemgrname ,b3.ENAME lvltwomgrname
from
base b1,
mgr m,
base b2,
base b3
where
b1.eid=m.eid
and b2.eid=m.mgrlvl1
and b3.eid=m.mgrlvl2
EID     ENAME     LVLONEMGRNAME     LVLTWOMGRNAME
1     A     C     D
2     B     A     E
3     C     D     B
It provided the output fine. But i used 2 "Base" table instances to populate 2 level manager names. In the actual requirement of selecting 20 manager names it makes me to add 20 instances of "Base" table.
With out creating 20 instances, we can use PL/SQL function and achieve the output.
Is there any other way to do this using SQL ? Please advise me

select m.eid, b1.ENAME,
       max(decode(b2.eid, m.mgrlvl1, b2.ENAME)) lvlonemgrname,
       max(decode(b2.eid, m.mgrlvl2, b2.ENAME)) lvltwomgrname
from base b1, mgr m, base b2
where b1.eid=m.eid
  and b2.eid in (m.mgrlvl1, m.mgrlvl2)
group by m.eid, b1.ENAME

Similar Messages

  • JDBC Problem: "select * from NAMES for update of FIRSTNAME"

    I am using Oracle 8 and JDBC thin driver. Is there any reason
    why when I try to use the statement:
    "select * from NAMES for update of FIRSTNAME"
    it does NOT work in JDBC?
    However when I do the statement in SQL-Plus it works fine.
    If anyone has used this statement with success, please let me
    know that it actually works, so that I know there is something
    wrong with me!
    Any code snippets would be very helpful.
    Could it be the thin driver?
    Please help! Thanks in advance.
    null

    Thomas Gutzmann (guest) wrote:
    : James,
    : for this command you need transactional control, which is not
    : possible with JDBC - if I'm not wrong. You can circumvent it
    with
    : something like:
    : select x into vOld from t where id=4711;
    : vNew := 0.815;
    : update t set x = vNew where id = 4711 and x = vOld;
    : Another option would be to write a stored PL/SQL procedure that
    : runs the whole transaction.
    : Cheers
    : Thomas
    : James Ward (guest) wrote:
    : : I am using Oracle 8 and JDBC thin driver. Is there any
    reason
    : : why when I try to use the statement:
    : : "select * from NAMES for update of FIRSTNAME"
    : : it does NOT work in JDBC?
    : : However when I do the statement in SQL-Plus it works fine.
    : : If anyone has used this statement with success, please let me
    : : know that it actually works, so that I know there is
    something
    : : wrong with me!
    : : Any code snippets would be very helpful.
    : : Could it be the thin driver?
    : : Please help! Thanks in advance.
    I don't think this is correct. I have used select for update
    with no problems. you can send a "set transaction control"
    via sql, I believe, but you shouldn't need to do so...
    Maureen
    null

  • Standard Dialog to select manager name

    Hi,
      I am new to Adobe forms. My requirement is to activate already existing standard dialog to choose the manager name as  a signee that will appear in the form. The form is a standard T1 form. Form name is HR_RU_T1.
    Please let me know.
    Thanks,
    Sri

    HI,
    check this program.
    <b>
    report ZTEST2.
    data:  file type string,
           path type string,
           file_path type string.
    data: itab type standard table of cskt.
    start-of-selection.
      SELECT * FROM cskt INTO TABLE itab.
      call method cl_gui_frontend_services=>file_save_dialog
          exporting
                    FILE_FILTER = '*.PDF'
          changing FILENAME = file
                   path     = path
                   fullpath = file_path.
      check not file_path is initial.
      call method cl_gui_frontend_services=>gui_download
        exporting    filename                = file_Path
                      WRITE_FIELD_SEPARATOR = 'X'
         changing    data_tab                = itab.
    </b>
    REgards,

  • Dynamically setting manager name for trap

    As per the SEA documentation, trap destinations are specified through master agent configuration file and need to be set before starting master agent.
    We want add more managers dynamically i.e. after master and subagent are started and communicating with one manager.
    Does snmpdx provide any MIB variable to "set" the manager name? Is there any other alternative such as command line parameter or API to set the manager name?
    Thanks
    Dhananjay

    Hi,
    This feature is not supported in SEA. All the configuration should be done before starting master agent.
    To register the subagent, you can use any of the following two methods.
    * Static method : The master agent reads agent resource files. This resource
    file contains an entry for each subagent.
    * Dynamic method : The master agent receives the information from the subagents. The subagent sends a SET request containing the MIB objects needed to register with the Master Agent, through the use of the registration API.
    Using SEA, there is no way you can add the managers dynamically for traps.
    I suggest you may have look on new product from SUN i.e SunMC( Sun Management Center) which has lot of new features.
    HTH.
    Thanks,
    Santosh

  • How to dynamically populate a manager name and level for any user who login

    Hi All,
    I need some help in doing this in my DB:
    Table 1 is the the manager hierarchy {which basically shows the structure of every employee's org).
    Table 2 is a list of all people manager ( all these usernames will also be in table 1). What i need to find is using the username from Table 2, the highest level that username exists in the manager hierarchy.
    For ex:
    Table 1: { What this shows is Sam is CEO and Jeff reports to him. So for Sam, he will exist on all 15 levels and Jeff will have Sam has his top level manager and then Jeff will repeat for all remaining levels till 15.
    Manager Level 0  Level 1  Level 2 Level 3...Level15
    Sam                       Sam     Sam     Sam         Sam
    Sam                        Jeff     Jeff        Jeff          Jeff
    Now in Table 2:
    User Name   Manager Level/Name
    Sam               Manager Level 0 Sam
    Jeff                 Manager Level 1 Jeff
    As you see, for each user name in Table i want to populate their high level from the manager hierarchy {their record in manager hierarchy).
    Hope This helps to clear the confusion.
    Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hello,
    this is the forum for the tool {forum:id=260}. Please mark this question as answered, so others know that they can ignore it.
    Then post again in {forum:id=75}
    Regards
    Marcus

  • Need Selection variable name for "System Year - 1"

    Hi All,
    I have Fiscal Year field in the selection screen of a custom program. The value of this field comes from system variable.
    I need to create a variant where this fiscal year should have the value "Current year - 1".
    This has to be done using Selection Variable. Currently there is no such variable in the F4 help (TVARV table).
    Please tell me if there is a way to get such a selection variable...

    Hi Tolga,
    The selection screen parameter is defined as:
    parameters: p_gjahr        type gjahr obligatory memory id gjr,
    I cannot use the FM in the AT SELECTION SCREEN ON VALUE-REQUEST.
    When you create a variant for the program.. click button "Variant Attributes" - Here the checkbox for Selection variable is ticked for this field. Now click "Selection Variables". here we can provide the variable name which comes from TVARV table.
    I need this Selection variable. I am not allowed to do any program changes.

  • Exchange 2010 - Selecting display names for users with multiple mailboxes

     Hi all,
    This isn't so much of a problem, but more of a "What is the best way to handle this" sort of thing.
    I have a client with Exchange 2010 and multiple domains. Because they must be able to send as each domain, I have them setup with individual accounts/mailboxes for each domain. We're at a point that they have three domains which means three accounts per
    user and three listings in the GAL. Their original accounts shows up as Smith, John. The second domain added shows up as First last. I'm at a loss what to use for the third. They want each account to show up in the GAL so that other users can send account
    specific stuff to them if needed, but I'm trying to figure out how to keep this relatively organized and not make the name on outbound emails too convoluted.
    Any suggestions on a format I can use that will make these accounts stand out from each other in the GAL, but not be a hot mess on the recipient end either?

    Smith, John (Company A)
    Smith, John (Company B)
    Smith, John (Company C)
    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."

  • Urgent please help: what is the table name for cash management reports?

    I am wondering what the table name for cash management reports is. I am trying to figure out then if I have any missing.
    Please help.

    I checked MSEG table. But, I didn't find any field for date.
    Can you tell me field name.
    Regards
    Siva

  • Unable to find Database Item Name for Employee Category at assignment level

    Hi,
    What is the database item name for employee category at assignment level.
    I want to call employee category colomn of assignment level in fast formula.
    Thanks in advance...

    It seems that there are no seeded database items available for employee category, the only other option is to write a plsql function at the database level which will return the employee category for a given assignment_id & effective dates. Link this plsql function to a Fast formula function. You can use the newly created fast formula function in your fast formula.
    Regards,
    Senthil

  • How to change host name for management agent.

    Hi,
    I 've installed management agent for oracle, it's a part of Oracle Management Framework, but I have to change host name.
    I know how to change port number, but I've no idea how to change host name.
    Have you got any idea?
    Thank you in advance.
    Matin

    Hi,
    you can change it in System Landscape directory.
    Go to the http:yourportal.com:50000/sld
    then click on the Landscape and update the new host name.
    Raghu

  • How to find ContentDb Name for any of the service application (e.g. User profile , Managed metadata , etc) programmatically in a farm ?

    Hi,
    I have a application where i need to display Name for all the service application. Specifically i need to get the size of user profile service application and Managed metadata service application name.
    Please guide me. :)
    Thanks and Regards:
    Sanjay

    You can use 
    http://blogs.technet.com/b/tothesharepoint/archive/2011/12/19/find-active-databases-used-by-sharepoint-server-2010.aspx
    Get-SPDatabase | Sort-Object disksizerequired -desc | Format-Table Name”
    http://webcache.googleusercontent.com/search?q=cache:kMHQXNGmjcwJ:sharepointstruggle.blogspot.com/2011/08/programmatically-enumerating-databases.html+&cd=1&hl=en&ct=clnk&gl=in
    using(SPSitesite
    = newSPSite(url))
    using(SPWebweb
    = site.OpenWeb())
    SPFarmf
    = site.WebApplication.Farm;
    foreach(SPDatabaseServices
    inf.Services.OfType<SPDatabaseService>())
    Console.WriteLine(string.Format("Found
    Database service {0} of type {1}",
    s.Name, s.GetType().Name));
    foreach(SPDatabaseServiceInstancespdsi
    ins.Instances)
    Console.WriteLine(string.Format("|-Found
    Database Service Instance {0} ({1})",
    spdsi.DisplayName, spdsi.Name));
    foreach(SPDatabasespdb
    inspdsi.Databases)
    Console.WriteLine(
    string.Format("  |-DB: {0}\r\n    |-TYPE: {1}\r\n   
    |-HOST: {2} ",
    spdb.Name.Length
    > 70? spdb.Name.Substring(0,
    65)
    + "...": spdb.Name,
    spdb.GetType().Name, spdb.Server.Name)
    http://social.msdn.microsoft.com/Forums/en-US/61e4e56e-e373-4167-ba97-e0f411feefe9/how-can-we-programmatically-find-the-names-of-sharepoint-databases

  • Managed path for host named site collection is farm level or web application level?

    Hi,
    I would like to get advice.
    I created a webapplication for host named site collections.
    these are my host named site collections (except http://sp2013) under my webapplication
    Root Site Collection: http://sp2013
    Site Collection: portal1.sg
    Site Collection: portal1.sg/research
    Site Collection: portal1.sg/intranet
    research and intranet managed paths are farm level
    all my host named site collection will be accessed by http and https except "intranet" site collection will be only accessed by https
    so I changed the Intranet zone for site collection using Set-SPSiteUrl
    Set-SPSiteUrl (Get-SPSite "http://portal1.sg") -Url "https://portal1.sg" -Zone Intranet
    Set-SPSiteUrl (Get-SPSite "http://portal1.sg/research") -Url "https://portal1.sg" -Zone Intranet
    Set-SPSiteUrl (Get-SPSite "http://portal1.sg/intranet") -Url "https://portal1.sg/intranet" -Zone Intranet
    Now I need to create "search" site collection for "Enterprice Search Center"
    My question is that for the "search" managed path ... should i use farm level or web application level?
    "search" site collection will be will be accessed with both http and https also.
    Thanks a lot!

    managed path for HNSC is farm level and u can have 20 managed path
    while managed path for path based is 20 per web application in your case if you are going to have a a separate web application for search then u will use web app
    Kind Regards,
    John Naguib
    Technical Consultant/Architect
    MCITP, MCPD, MCTS, MCT, TOGAF 9 Foundation
    Please remember to mark your question as answered if this solves your problem

  • Table name for Case Management

    Can anyone please help me out with all the required table names for implementing CASE MANAGEMENT....... the table information which contains status, Texts, Description,activities, Bus.transactions,priorities,and etc of Cases.....

    Hi Daniel,
    First of all, you need to create status Profile, Text Profile, Attribute Profile etc.,
    Later you have to create a CASE TYPE.
    while creating a Case Type you will mention the above created Status, Text and Attribute Profile names.
    Later while reating the Case you need to choose this particular Case Type which you have created.
    Because, Case is based on CaseType.
    Steps for creating Status, Text , Attribute Profiles will be available in the IMG Activity. Do refer.
    Regards,
    Eswari.

  • Form Name for Warehouse Management - URGENT

    Hi
    Can anybody pls let me know Form Names, Print Program Names for the following:
    1. Stock Removal
    2. Stock Placement
    3. Warehouse Movement

    Check the Transaction NACE --> V2 (Shipping) --> Output Types
    There you can see all the Stock related Output types. By SELECTing the output type and pressing Processing Routines you can get the Form Name and print program details...

  • Jdbc mysql "select ... for update" and isolation level...

    Dear, I am now writing an application, in which some worker threads will get a waiting job from database (mysql) and perform the processing.
    To avoid workers getting the same job id, I have studied the topics about locks, isolation level, and something like "select ... for update".
    The storage engine being used is innoDB. Actually the problem seems solved after using "select ... for update" to get the id, but I am just curious that do I also need to care about the isolation level. It is because when I do some experiments by setting the isolation level to serializable, but NOT using "SELECT ... FOR UPDATE" (just simple select), exception something like "deadlock found and try to restart transaction" occurs. Is there any relationship between these two things? Any comments are welcome!! Thanks!!!

    ashipj wrote:
    can u plz provide me with the code (connection string). Am new to Mysql.
    And also the driver u are using.
    Thank youDon't hijack other's topics. Kindly start your own. Don't do that before you read the [Sun JDBC tutorial|http://java.sun.com/docs/books/tutorial/jdbc/index.html] and the [MySQL JDBC documentation|http://dev.mysql.com/doc/refman/5.0/en/connector-j.html].

Maybe you are looking for

  • $tmp package for ABAP proxy

    I am trying to invoke ABAP Client proxy. Can I use $TMP package or do I need to specify a different package? Also if local package is allowed, do I need to set up USE Access?

  • Motion Basic 3D Problem

    I would like to move the x-axis or the anchor point of the basic 3D-filter to the base of an object, enabling the object move around it's base instead of it's center, is this possible? If so, how do I do it? If not, how else can I create this effect?

  • SAP Course for beginner in London

    Hi, I am in Shipping & Logistics business and want to change into SAP. Although I have over 9 years experience in the business I have been told that I need to support it with certificate in MM, LE or SRM. I tried to find a course over the internet an

  • Win7 won't install, black screen - boot camp

    Hey, I have burned a win7 .iso file to a dvd and was going to install windows with boot camp. After the partition was done my iMac (24-inch, Early 2008) restarted and the screen went black with a white line blinking in the upper left corner. Does any

  • Nokia 5800 secondary camera

    Hi, Can anyone please let me know how to activate/select the secondary camera for capturing images present on the front side of Nokia 5800 express music??? By default only the back camera functions while taking pictures. How to take pictures from the