How we we display list the employees in the reporting hierarchy order? Need T-SQL

Rather than see everyone by level, it seems the natural way you might want to report them is in reporting-line hierarchy.Create table #test_t (ManagerID int,EmployeeID int ,Title varchar(100),Level int)
Insert into #test_t
select NULL,1,'Chief Executive Officer',0 Union All
select 273,285,'Pacific Sales Manager',2 Union All
Select 273,16,'Marketing Manager',2 Union All
select 274,275,'Sales Representative',3 Union All
select 274,276,'Sales Representative',3 Union All
Select 16,23,'Marketing Specialist',3 Union All
select 273,274,'North American Sales Manager',2 Union All
select 285,286,'Sales Representative',3 Union All
Select 1,273,'Vice President of Sales',1 ManagerID EmployeeID Title                         Level
NULL      1          Chief Executive Officer       0
1         273         Vice President of Sales       1
273       16          Marketing Manager             2
16        23          Marketing Specialist          3
273       274         North American Sales Manager  2
274       275         Sales Representative          3
274       276         Sales Representative          3
273       285         Pacific Sales Manager         2
285       286         Sales Representative          3I need TSQL query for this kind of result set. Level more than 3 we have in data.

Your query display the following result. See the my required result set accordingly Level wise. 
ManagerID   EmployeeID  Title                                           Level
NULL        1           Chief Executive Officer                             1
1           273         Vice President of Sales                              2
273         285         Pacific Sales Manager                              3
273         16          Marketing Manager                                  3
273         274         North American Sales Manager                3
274         275         Sales Representative                               4
274         276         Sales Representative                               4
16          23          Marketing Specialist                                  4
285         286         Sales Representative                               4
I need following display order 
ManagerID EmployeeID Title                         Level
NULL      1          Chief  Executive Officer       0
1         273         Vice President of Sales       1
273       16          Marketing Manager             2
16        23          Marketing Specialist          3
273       274         North American Sales Manager  2
274       275         Sales Representative          3
274       276         Sales Representative          3
273       285         Pacific Sales Manager         2
285       286         Sales Representative          3

Similar Messages

  • HT201441 if the employee has been terminated and I need to reuse the phone and have no ability to contact them, how can I erase the phone?

    if the employee has been terminated and I need to reuse the phone and have no ability to contact them, how can I erase the phone?

    Welcome to the Apple community.
    Contact AppleCare (or Apple ID Support), upon speaking to an operator you should explain that your problem is related to your Apple ID, this way you will not be charged for assistance, even if you don’t have an AppleCare plan.
    I'm not exactly sure what procedures are in place for such events but Apple can assist in such cases, but it may take a while and you may need to provide proof of purchase and other corporate documents.
    For future reference your best tactic might be to use Apple Configurator to set up all your companies devices. You can set the password for 'Find my Phone' to be identical for all your devices, whilst allowing the user to use their own password for the remainder of the iCloud services.

  • Linking the Employees and Departments Reports - 2Day+ tutorial

    Hi Guys,
    I am APEX newbie and started off with the 2DAYPLUS tutorial. Got stuck in the "Linking the Employees and Departments Reports" part.
    I followed the instructions (even did it twice) where you you create a select list of department which will populate your employee table according to the Department you select.
    Can't seem to make it work. So when I select Accounting or anything form the drop down list, the Employee table remains unchanged. Anyone else had similar issue? Not sure if its me or there is a step or two missing in the tutorial.
    Section in TUTORIAL: http://www.sloug.org/i/doc/TDPAX/td_bldemprpts.htm#BCECEDHD

    :::SOLVED:::
    For search engines:
    I missed the part:
    b.Select List Control Type - Select Select List with Submit and click Next.
    Well actually didn't miss it, there wasn't that option in my APEX installation (maybe tutorial is a bit outdated for earlier version of APEX).
    If you have already created the Item and it does not work then:
    1) Go to EDIT for that P3_DEPARTMENT_ID
    2) Scroll down to SETTING section
    3) In PAGE ACTION WHEN VALUES CHANGE choose SUBMIT.
    this achieves the same result as (b) above.

  • To get the employee with the largest salary

    Is it possible to find the employee with the largest salary without using a subquery???

    Well, of course there are many tables with employees in them, but from the
    phrasing of the question (find highest salary, but can't use subquery!) I think we can
    conclude it's the emp table in question here :-)... and I have no sample schemas in any of my databases. And now? ;)
    I guess it's absolutely ok to ask for actual data. Moreover, it should be provided by OP when posting the question.
    I'm not here because I love to make (more or less) educated guesses.

  • How can I display date+time and not the point number in excell?

    Hi everyone,
    Could anybody tell me how I can save date + time to a file, so that  I can display on a diagram(excel) : date+time in (ox) and data (oy)? :
    My program sets in (ox) the point number and not the date+time....( although  date and time are written correctly in the column...)
    Any help would be great,
    Thanks,
    regards,
    Marc

    hi there,
    excel uses 01.01.1900 00:00 as the time offset, LabVIEW uses 01.01.1904 02:00, so you can't display the correct datetime in excel when you write the time as a fractional number of seconds from LabVIEW. you must format the datetime in LabVIEW to a string and write that to the column. use the "Format Date/Time String" - function and for example "%d.%m.%Y %H:%M:%S%3u" as the format string (see the functions help for more examples). you also could format your data to a string using "Format Into String" - function and write the file as a 2D string array. the decimal point you have to use depends on your system and its settings, but you can specify the decimal point in the Format string like "%.;%f" (means fractional number with point as decimal point).
    best regards
    chris 
    Best regards
    chris
    CL(A)Dly bending G-Force with LabVIEW
    famous last words: "oh my god, it is full of stars!"

  • How can I display a formula variable in the report?

    Hi,
    I have a requirement to display a formula variable value in the report. When the user runs a report this variable value should be called once and displayed below the report title or in a specified cell. Is it possible something like this could be done? if yes, can someone tell me how can I achieve this functionality. I appreciate your time and effort with points.
    Thanks,
    Rao.

    Hi Bhanu,
    In the query properties you can only see text variables and not the formula variables. If I define my number of working days as text variable and I can display in the report. However, I need to use this variable in some calculation in the report, so it has to be formula variable in order to use in calculations. I appreciate your input with points.
    Thanks,
    Rao.

  • Need to know how to iterate a list of field from the req xml in page servic

    Hi All,
    Please help me out with java code in which i am able to iterate a list of field coming in the request xml to my page service class under read(Pageheader header) method of mine queryPagemaintenace class.
    package com.splwg.cm.domain.pageService;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.List;
    import com.ibm.icu.math.BigDecimal;
    import com.splwg.base.api.businessObject.BusinessObjectDispatcher;
    import com.splwg.base.api.businessObject.BusinessObjectInstance;
    import com.splwg.base.api.businessObject.COTSInstanceListNode;
    import com.splwg.base.api.datatypes.Date;
    import com.splwg.base.api.lookup.BusinessObjectActionLookup;
    import com.splwg.base.api.service.DataElement;
    import com.splwg.base.api.service.ItemList;
    import com.splwg.base.api.service.PageHeader;
    import com.splwg.shared.common.ApplicationError;
    import com.splwg.shared.environ.FieldDefinition;
    import com.splwg.shared.environ.ListDefinition;
    import com.splwg.shared.logging.Logger;
    import com.splwg.shared.logging.LoggerFactory;
    * @author
    @QueryPage (program = CMUSER, service = CMUSER,
    * body = @DataElement (contents = { @ListField (name = USER_GROUP_LIST)
    * , @ListDataField (name = USR_GRP_ID)
    * , @DataField (name = MESSAGE_TEXT)
    * , @DataField (name = USER_ID)
    * , @DataField (name = PASSWORD)
    * , @DataField (name = LAST_NAME)
    * , @DataField (name = FIRST_NAME)
    * , @DataField (name = USER_TYPE_FLG)
    * , @DataField (name = EMAILID)}),
    * actions = { "add"
    * ,"read"
    * , "delete"
    * , "change"},
    * header = { @DataField (name = USER_TYPE_FLG)
    * , @DataField (name = EMAILID)
    * , @DataField (name = LAST_NAME)
    * , @DataField (name = FIRST_NAME)
    * , @DataField (name = PASSWORD)
    * , @DataField (name = USER_ID)},
    * headerFields = { @DataField (name = USER_TYPE_FLG)
    * , @DataField (name = USR_GRP_ID)
    * , @DataField (name = EMAILID)
    * , @DataField (name = LAST_NAME)
    * , @DataField (name = FIRST_NAME)
    * , @DataField (name = PASSWORD)
    * , @DataField (name = USER_ID)},
    * lists = { @List (name = USER_GROUP_LIST, size = 100, includeLCopybook = false,
    * body = @DataElement (contents = { @DataField (name = USR_GRP_ID)}))},modules = {})
    public class CMUSER extends CMUSER_Gen {
    public static final Logger logger = LoggerFactory.getLogger(CMUSER.class);
         DataElement root = new DataElement();
         PageHeader page = new PageHeader();
         protected DataElement read(PageHeader header) throws ApplicationError{
    I want to know how can i iterate this USER_GROUP_LIST in my read method and get the USR_GRP_ID field data from it.
    A Prompt reply from your end will help me to resolve this issue

    Guru Sir,
    i tried to override the add() method of the framework in that i was able to iterate the field from the list. But now the i am facing there is that i am not able to send back the response to the external system in XML format. I am getting a blank response in my SOAP UI Tool while testing here is the code:
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.List;
    import com.ibm.icu.math.BigDecimal;
    import com.splwg.base.api.businessObject.BusinessObjectDispatcher;
    import com.splwg.base.api.businessObject.BusinessObjectInstance;
    import com.splwg.base.api.businessObject.COTSInstanceListNode;
    import com.splwg.base.api.datatypes.Date;
    import com.splwg.base.api.lookup.BusinessObjectActionLookup;
    import com.splwg.base.api.service.DataElement;
    import com.splwg.base.api.service.ItemList;
    import com.splwg.base.api.service.PageHeader;
    import com.splwg.shared.common.ApplicationError;
    import com.splwg.shared.logging.Logger;
    import com.splwg.shared.logging.LoggerFactory;
    * @author
    @QueryPage (program = CMUSER4, service = CMUSER4,
    * body = @DataElement (contents = { @DataField (name = MESSAGE_TEXT)
    * , @DataField (name = PASSWORD)
    * , @DataField (name = USER_ID)
    * , @DataField (name = LAST_NAME)
    * , @DataField (name = FIRST_NAME)
    * , @DataField (name = USER_TYPE_FLG)
    * , @DataField (name = EMAILID)
    * , @ListDataField (name = USR_GRP_ID)
    * , @ListField (name = USER_GROUP_LIST)}),
    * actions = { "add"
    * , "delete"
    * , "change"
    * , "read"},
    * header = { @DataField (name = USER_ID)
    * , @DataField (name = MESSAGE_TEXT)},
    * headerFields = { @DataField (name = USER_ID)
    * , @DataField (name = MESSAGE_TEXT)},
    * lists = { @List (name = USER_GROUP_LIST, size = 100,
    * body = @DataElement (contents = { @DataField (name = USR_GRP_ID)}))}, modules = {})
    public class CMUSER4 extends CMUSER4_Gen {
         public static final Logger logger = LoggerFactory.getLogger(CMUSER4.class);
         DataElement root = new DataElement();
         PageHeader page = new PageHeader();
         protected PageHeader add(DataElement item) throws ApplicationError{
              BusinessObjectInstance boInstance = BusinessObjectInstance.create("CM-USER");
              String USR_GRP_ID = null;
              try{
              logger.info("Data coming from the Service into the Application is :"+item.get(STRUCTURE.USER_ID));
              logger.info("Data coming from the Service into the Application is :"+item.get(STRUCTURE.FIRST_NAME));
              logger.info("Data coming from the Service into the Application is :"+item.get(STRUCTURE.LAST_NAME));
              logger.info("Data coming from the Service into the Application is :"+item.get(STRUCTURE.EMAILID));
              // logger.info("Data coming from the Service into the Application is :"+getInputHeader().getString(STRUCTURE.list_USER_GROUP_LIST.USR_GRP_ID));
              // Iterator it = STRUCTURE.
              ItemList sourceList = item.getList(STRUCTURE.list_USER_GROUP_LIST.name);
              List userGrpID = new ArrayList();
              logger.info("The Size of the User Group List here is :"+sourceList.size());
              Iterator iter;
              if ((sourceList != null) &&
              (sourceList.size() > 0)) {
              for (iter = sourceList.iterator(); iter.hasNext(); ) {
              DataElement myItem = (DataElement)iter.next();
              USR_GRP_ID = myItem.get(STRUCTURE.list_USER_GROUP_LIST.USR_GRP_ID);
              logger.info("The User Group Id coming in the List here is :"+USR_GRP_ID);
              logger.info("Data coming from the Service into the Application is :"+item.get(STRUCTURE.PASSWORD));
              boInstance.set("user", item.get(STRUCTURE.USER_ID));
              boInstance.set("firstName", item.get(STRUCTURE.FIRST_NAME));
              boInstance.set("lastName", item.get(STRUCTURE.LAST_NAME));
              boInstance.set("emailAddress", item.get(STRUCTURE.EMAILID));
              // COTSInstanceList userGrpList = boInstance.getList("userGroupUser");
              // COTSInstanceListNode userGroupList = userGrpList.newChild();
              COTSInstanceListNode userGroupList = boInstance.getList("userGroupUser").newChild();
              userGroupList.set("userGroup", USR_GRP_ID);
              logger.info("Data coming from the Service into the Application is :"+userGroupList.toString());
              /*boInstance.set
              boInstance.set("userGroup", getInputHeader().getString(STRUCTURE.HEADER.USR_GRP_ID));*/
              // UserTypeLookup.constants.TEMPLATE_USER
              //if(element.get(STRUCTURE.USER_TYPE_FLG))
              //boInstance.set("user", element.get(STRUCTURE.));
              boInstance.set("dashboardWidth","200");
              boInstance.set("homeNavigationOption","CI0000000574");
              boInstance.set("language","ENG");
              boInstance.set("toDoEntriesAge1", new BigDecimal(50));
              boInstance.set("toDoEntriesAge2",new BigDecimal(100));
              boInstance.set("displayProfileCode", "NORTHAM");
              String expirationDate = "2100-12-31";
              String[] array = expirationDate.split("-");
              userGroupList.set("expirationDate",new Date(Integer
                             .parseInt(array[0]), Integer
                             .parseInt(array[1]), Integer
                             .parseInt(array[2])));
              //boInstance.set("userGroupUser", userGroupList);
              COTSInstanceListNode roleUserList = boInstance.getList("roleUser").newChild();
              roleUserList.set("toDoRole","F1_DFLT");
              COTSInstanceListNode dataAccessList = boInstance.getList("dataAccessUser").newChild();
              dataAccessList.set("dataAccessRole","***");
              String expiryDate = "2100-01-01";
              String[] array1 = expiryDate.split("-");
              dataAccessList.set("expireDate",new Date(Integer
                             .parseInt(array1[0]), Integer
                             .parseInt(array1[1]), Integer
                             .parseInt(array1[2])));
              BusinessObjectDispatcher.execute(boInstance,
                             BusinessObjectActionLookup.constants.FAST_ADD);
              page.put(STRUCTURE.HEADER.MESSAGE_TEXT, "User Added Successfully");
              page.put(STRUCTURE.HEADER.USER_ID,item.get(STRUCTURE.USER_ID));
              }catch(Exception e){
                   e.printStackTrace();
                   page.put(STRUCTURE.HEADER.MESSAGE_TEXT, "Caught Exception in the ORMB System. Please reach out to the Admin"+e.getMessage());
                   page.put(STRUCTURE.HEADER.USER_ID,item.get(STRUCTURE.USER_ID));
              return page;
    If you can help me to find out what went wrong here while sending the response back it can close my issue.

  • When simulating a circuit, how do I display current and voltage on the circuit?

    Hello, how do I get Current and Voltage to display on the circuit design without using meters?

    saxyman123,
    You can use probes (yellow instrument towards the end of the instruments toolbar) and then set the properties.  You can choose to display just current and voltage.
    Regards,
    Pat Noonan
    National Instruments

  • How to delete playlists listed under iPod on the Preferences panel?

    I have a pesky problem. When I synced my iPod, I got all sorts of playlists of CD's I've added to iTunes in the past (dozens). So, I deleted them in iTunes and re-synced my iPod, only to find the lists there again. I noticed that those old playlists are listed on the iPod panel in Preferences. I suppose I could solve the problem by manually managing my iPod, which is what I normally do, but from time to time I'd like to do an automatic sync without all those old playlists getting put back on my iPod.
    The question is: How can I delete the playlists listed on the iPod panel of Preferences?
    Robert

    Hi Robert,
    Welcome to Apple Discussions
    So you had playlists in iTunes and the synced to the iPod.
    You then deleted then from iTunes but they still appear in the iPod Preferences.
    I guess they must be unselected or you would get an error trying to sync the iPod.
    I don't know how to get them out of the Preferences.
    Maybe you need to ask Apple unless anyone else knows?
    Regards,
    Colin R.

  • How do I display multiple pdf documents in the same window?

    I am sure that this question has been asked many times before, but I have searched the forums and the online help documentation for nearly 45 minutes without a satisfactory answer.
    I have just installed the trial version of acrobat pro and I want to open multiple documents in the same window but I can't seem to find out how to do it.
    Can someone tell me how?
    Thanks

    This is the worst thing to happen to acrobat, in my opinion.
    The clutter that it creates on my computer and the fact that i cant even see the document title when I have a bunch of them open (because the task bar is too full) is unacceptable.
    I never would have changed from Acrobat 8 if I had known, and now I cant switch back (company license).
    The latest thing i can find about addressing it is here:
    http://kb.adobe.com/selfservice/viewContent.do?externalId=kb405108&sliceId=1
    which was in november 2008....
    why hasnt any thing else been done about it?  I just spent 45 minutes being sent to different departments over the phone, only to be told to submit a feature request.
    Please do this if you havent already:
    http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

  • How do I display an informative message to the user on Oracle Forms?

    I have been asked to create a database trigger to fire when a user tries to update a column with existing data in it. If the column however has no data in it then the user can update the column with a value.
    I tried using the RAISE_APPLICATION_ERROR technique but somehow no message shows up on the frond end of the form when a user tries to update a column with existing data in it. The rest of the trigger works fine. It does not allow a user to update a column with existing values in it, yet it allows user to update column with no values in it.
    My problem is displaying a message that reads like this :''Column value must must be 100 "
    Here is parts of my code.
    CREATE OR REPLACE TRIGGER trigger_name
    IF :NEW.ATTRIBUTE2 IS NOT NULL AND :NEW.ATTRIBUTE2 <> NVL(:OLD.ATTRIBUTE2, :NEW.ATTRIBUTE2) THEN
    RAISE_APPLICATION_ERROR(-20002, 'Column value must must be : ' || :OLD.ATTRIBUTE2);
    END IF;
    Now i have tried this the syntax below. It does bring up a message on the front end of the form but it is not the message i have in mind.
    IF :NEW.ATTRIBUTE2 IS NOT NULL AND :NEW.ATTRIBUTE2 <> NVL(:OLD.ATTRIBUTE2, :NEW.ATTRIBUTE2) THEN
    FND_MESSAGE.set_name('FND', 'Column value must
    be '|| :OLD.ATTRIBUTE2);
    FND_MESSAGE.set_token('MSG', 'r21_AP_INVOICES_TRIGGER()
    exception: ' || SQLERRM);
    FND_MESSAGE.RAISE_ERROR;
    END IF;
    Does anyone has any idea?
    thx

    Unfortunately I do not have access to the Form properties. I was only asked to write a trigger to prevent a user from updating a field with data in it, and displaying a message saying that the user cannot update such a column when the user tries to update such a column.
    I know that changing the form properties might be an easier option, but unfortunately i have to everything with the help of a trigger
    Message was edited by:
    user644929

  • How can I display URL parameters ({module_url}) in the Order Receipt page?

    I'm trying to display extra information in my Order Receipt page by passing a value in the URL from the Order Registration form.
    The parameter is adding to my URL and the form is processing as expected, but I can't seem to pull that value out of the URL to display on the page.
    I've used {module_url, myValue} but it comes up empty.
    Am I doing something wrong or can you not use this module in the Order Receipt page?

    Thanks Liam. Another thing BC could look at implementing is more flexibility with the E-Commerce layouts

  • How can we display below mention control in the selection screen

    I want to display a container in the selection screen. (the container which we can use/get in the alv out put when we select a ascending/decending sort buttons for filtering of sort order).
    thanks in advance.
    sree

    simply at selection-screen output. event do the following coding.
    1. create a docking container
    2. create you control on to the container.
    create object docking
      exporting
      repid = repid
      <b>dynnr = sy-dynnr</b>  side = cl_gui_docking_container=>dock_at_right
      extension = '200'
      exceptions
      cntl_error = 1
      cntl_system_error = 2
      create_error = 3
      lifetime_error = 4
      lifetime_dynpro_dynpro_link = 5.
    if editor is initial.
      create object editor exporting parent = docking
                                     wordwrap_mode =
                         cl_gui_textedit=>wordwrap_at_fixed_position
                                     wordwrap_position = 256
                                     max_number_chars = 100000.
    endif .
    Regards
    Raja

  • How to stop this list from reverting to the short version every time I click on an item?

    I'm not sure where I should post this to get a response so I'll try here.
    Every time I make the list of topics longer, and then click on a topic to read it, then click back to the main list, I get sent back to the first (short) list of topics in the forum instead of the longer list I was looking at.
    What am I doing wrong?

    Tom in London wrote:
    I'm not sure where I should post this to get a response so I'll try here.
    This is the place.
    Every time I make the list of topics longer, and then click on a topic to read it, then click back to the main list, I get sent back to the first (short) list of topics in the forum instead of the longer list I was looking at.
    Are you clicking the "More" button to do this? Try using the "Discussions" tab instead, and click the "Set as default tab" option. I never use the overview tab.
    .. and another thing: why can I no longer edit my own question, not even 10 seconds after I've posted it, if I momentarily go back to the main list and then return to my question?
    Did you check the upper right corner? The first post of a thread is "special". You can't edit it or report it from the normal location. You can report the thread via the upper right link. I think you can edit from there too.

  • How Do I Display Custom Document Properties On the Info - Properties Page

    Hi,
    I want to create a template using Microsoft Word 2010 that has fields similar to the Standard Document Property "Title" that can be used as a fillable form that repeats data throughout the document.  I need a custom document property field
    that you can fill out on the title page and will simultaneously change the same field that is in the header, footer, and file -> info -> properties page. 
    For example, I want to create a document property field called "Product ID #" that shows the title of the property on the file -> info -> properties page as "Product ID #" and the content to show up as the information
    a user entered into the field on the first page.
    Right now I have a standard document property that I am using as a field on the front page for the Title which has user defined content on the front page.  This field has default content I set up to be "Product Specification Template". 
    I inserted this field by using quick parts.  I want to be able to create a field that behaves like this called "Product ID #".  I understand you can create custom form fields that repeat using legacy fields, but I need a way for them
    to show changes instantly after you click away from the field, without having to "update field" where necessary.
    Anyone have any idea how to create custom document properties like this? Or even how to rename standard properties such as "Status" or "Subject"?
    Thanks

    What you're asking can't all be done without a macro. You can easily enough get body content to show in the header & footer via the judicious use of Styles and STYLEREF fields (and the changes are dynamic), but getting that info into the custom
    document property would require a macro. To that end, you might use a content control with a unique Style applied to it for the data input and a ContentControlOnExit macro to update the custom document property.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  • How can you display only one artboard in the Navigation Panel?

    I would like to be able take advantage of the Navigation Panel as a thumbnail view of the artwork I am illustrating. The Adobe Illustrator file has 5 art boards. Is there an option in the Navigation Panel to view the art board I am working with, alone? 

    > That could work if all of the group items were the same size.
    Why would that matter? Each GroupItem has its own controlBounds, height, width, position properties. Each Document has its own height, width, pageOrigin properties. The script would reference those properties to position the Group in the center of the document.
    JET

Maybe you are looking for