How to insert a new rows for missing rows

Hi,
I have data like below.Generally the heirarchy like Manager,Supervisor,clerk and Jr.clerk. But, some times clerk directly reports to Manager that time i need to show "no supervisor" when retrive the data. Is there any way can we do that by using the sql query instead writing the procedure or function.
The heirarchy is not only three levels. Just i have given a sample data.
Current data :
HrchyId                   Role                 Name
======                ========               =======
1                    Manager                     Scott
2                    Supervisor                 Mary
3                    Clerk                     Henry
3                    Clerk                     Tyson
1                    Manager                     Lee
3                    Clerk                     Murry
1                             Manager                      Kirk
4                             Jr Clerk                        Tony
Output:
HrchyId                   Role                 Name
======                ========               =======
1                    Manager                     Scott
2                    Supervisor                 Mary
3                    Clerk                     Henry
3                    Clerk                     Tyson
1                    Manager                     Lee
2                             No Supervisor               Null
3                    Clerk                     Murry
1                             Manager                      Kirk
2                             No Supervisor               Null
3                             No clerk                      Null
4                             Jr Clerk                        TonyAppreciated your help.
Thanks & Regards,
RM.

Something like this?
with x_roles
as   (           select 'Manager'    Role, 1 HrchyId from dual
       union all select 'Supervisor' Role, 2 HrchyId from dual
       union all select 'Clerk'      Role, 3 HrchyId from dual
       union all select 'Jr Clerk'   Role, 4 HrchyId from dual
,    x_employees
as   (           select 'Manager'    Role, 'Scott' Name, 1 Hrchyid_sq from dual
       union all select 'Supervisor' Role, 'Mary'  Name, 2 Hrchyid_sq from dual
       union all select 'Clerk'      Role, 'Henry' Name, 3 Hrchyid_sq from dual
       union all select 'Clerk'      Role, 'Tyson' Name, 4 Hrchyid_sq from dual
       union all select 'Manager'    Role, 'Lee'   Name, 5 Hrchyid_sq from dual
       union all select 'Clerk'      Role, 'Murry' Name, 6 Hrchyid_sq from dual
       union all select 'Manager'    Role, 'Kirk'  Name, 7 Hrchyid_sq from dual
       union all select 'Jr Clerk'   Role, 'Tony'  Name, 8 Hrchyid_sq from dual
,     x_hierarchy
as    ( select r.HrchyId
        ,      e.Role
        ,      e.Name
        ,      e.Hrchyid_sq
        from   x_employees  e
        ,      x_roles      r
        where  1=1
        and    r.role = e.role
,     x_missing_hrchy
as    (
        select Hrchyid_sq
        ,      HrchyId
        ,      Name
        ,      MissingHrchy
        from   (
                 select h.Hrchyid_sq
                 ,      h.HrchyId
                 ,      h.Name
                 ,      h.HrchyId - lag( h.HrchyId ) over ( order by h.Hrchyid_sq ) - 1  MissingHrchy
                 from   x_hierarchy  h
        where  1=1
        and    MissingHrchy > 0
select m.HrchyId - g.HrchyGen   HrchyId
,      'No ' || r.Role          Role
,      'Null'                   Name
,      m.Hrchyid_sq             Hrchyid_sq
from   x_missing_hrchy      m
,      ( select level HrchyGen
         from   dual
         ,      ( select max( MissingHrchy ) MissingHrchy from x_missing_hrchy ) m
         connect by level <= m.MissingHrchy
       )                    g
,      x_roles              r
where  1=1
and    g.HrchyGen <= m.MissingHrchy
and    r.HrchyId  =  m.HrchyId - g.HrchyGen
union
select h.HrchyId
,      h.Role
,      h.Name
,      h.Hrchyid_sq
from   x_hierarchy h
order by 4
,        1
   HRCHYID ROLE          NAME  HRCHYID_SQ
         1 Manager       Scott          1
         2 Supervisor    Mary           2
         3 Clerk         Henry          3
         3 Clerk         Tyson          4
         1 Manager       Lee            5
         2 No Supervisor Null           6
         3 Clerk         Murry          6
         1 Manager       Kirk           7
         2 No Supervisor Null           8
         3 No Clerk      Null           8
         4 Jr Clerk      Tony           8I've used the queries x_roles, x_employees and x_hierarchy to generate the data you've provided.
Query x_missing_hrchy determines for each Hrchyid_sq how many managers are missing:
with ..
select *
from    x_missing_hrchy
HRCHYID_SQ    HRCHYID NAME  MISSINGHRCHY
         6          3 Murry            1
         8          4 Tony             2Murry misses one supervisor and Tony misses two supervisors.
For each missing supervisor I need to create a row. For that I use the connect by clause:
with ..
select m.Hrchyid_sq
,      m.HrchyId
,      m.Name
,      g.HrchyGen
,      m.HrchyId - g.HrchyGen MissingHrcyId
from   x_missing_hrchy      m
,      ( select level HrchyGen
         from   dual
         ,      ( select max( MissingHrchy ) MissingHrchy from x_missing_hrchy ) m
         connect by level <= m.MissingHrchy
       )                    g
where  1=1
and    g.HrchyGen <= m.MissingHrchy
order by m.Hrchyid_sq
,        5
HRCHYID_SQ    HRCHYID NAME    HRCHYGEN MISSINGHRCYID
         6          3 Murry          1             2
         8          4 Tony           2             2
         8          4 Tony           1             3After that you just select the name of the missing role and add the original hierarchy to the set to get the requested output:
with ..
select m.HrchyId - g.HrchyGen   HrchyId
,      'No ' || r.Role          Role
,      'Null'                   Name
,      m.Hrchyid_sq             Hrchyid_sq
from   x_missing_hrchy      m
,      ( select level HrchyGen
         from   dual
         ,      ( select max( MissingHrchy ) MissingHrchy from x_missing_hrchy ) m
         connect by level <= m.MissingHrchy
       )                    g
,      x_roles              r
where  1=1
and    g.HrchyGen <= m.MissingHrchy
and    r.HrchyId  =  m.HrchyId - g.HrchyGen
union
select h.HrchyId
,      h.Role
,      h.Name
,      h.Hrchyid_sq
from   x_hierarchy h
order by 4
,        1
   HRCHYID ROLE          NAME  HRCHYID_SQ
         1 Manager       Scott          1
         2 Supervisor    Mary           2
         3 Clerk         Henry          3
         3 Clerk         Tyson          4
         1 Manager       Lee            5
         2 No Supervisor Null           6
         3 Clerk         Murry          6
         1 Manager       Kirk           7
         2 No Supervisor Null           8
         3 No Clerk      Null           8
         4 Jr Clerk      Tony           8Cheers Danny

Similar Messages

  • How to apply a new font for missing glyphs in another font?

    The situation:
    For an article, I want to use Font1, but some of the glyphs are missing in it, and are highlighted with pink boxes. Font2 have much more glyphs than Font1. I can apply Font2 manually for each of the missing glyphs, but it is tedious.
    Question:
    Is there a way for InDesign to do such substitution automatically? I.e., apply a default font, which can be specified by user, for all the missing glyphs.
    If not, how to search/find those missing glyphs with GREP or script? Since InDesign can identify the missing glyphs and marked them with pink boxes, it seems easily (not to identify the unicode ranges which seems not very easy) to find them using GREP, but I failed to find it.
    Any one know how to do this? Thanks.

    calvyan wrote:
    Is there a way for InDesign to do such substitution automatically? I.e., apply a default font, which can be specified by user, for all the missing glyphs.
    No. Alas, I might add. There is some sort of auto-catch, specific for Symbol symbols, but no-one knows how it works and you cannot manipulate it yourself.
    If not, how to search/find those missing glyphs with GREP or script?
    Not specifically, i.e., you cannot search for "any missing glyph". Add a GREP style which changes just the font (make sure it doesn't set the font style as well, or else your Bolds or Italics might disappear). Create a new Preflight profile that checks just for missing glyphs, so you won't miss any.
    None of this can be automated though.
    .. it seems easily (not to identify the unicode ranges which seems not very easy) to find them using GREP, but I failed to find it.
    InDesign's GREP flavor doesn't allow named Unicode blocks (http://www.regular-expressions.info/unicode.html), but I have successfully used character ranges to automatically set the font for Chinese, for example.

  • How to insert a new row in the middle of an set of rows

    Hi
    How to insert a new  row in the middle of an set of rows ? and How to Reset the line id after the new row added ?
    Regards,
    Sudhir B.

    Hai,
    just try this,
    Instead of using omatrix.Addrow(1,-1) use like
    omatrix.AddRow( RowCount , Position)
    RowCount
    The number of rows to add (default is 1)
    Position
    The position of the new rows (0-based; default is -1, meaning append row to the end)
    After adding rows in matrix For, sno.
    for i=1 to omatrix.visualrowcount
    otext=omatrix.getcellspecific("columnid",i)  '--where columnid is the unique id of the sno column
    otext.value=i
    next i
    Hope this helps you.
    Thanks & Regards,
    Parvatha Solai.N

  • Hi, how can i break the value for a row and column once i have converted the image to the array?????​??

    Hi, I would like to know how can i break the value for a row and column once i have converted the image to the array. I wanted to make some modification on the element of the array at a certain position. how can i do that?
    At the moment (as per attachhment), the value of the new row and column will be inserted by the user. But now, I want to do some coding that will automatically insert the new value of the row and the column ( I will use the formula node for the programming). But the question now, I don't know how to split the row and the column. Is it the value of i in the 'for loop'? I've  tried to link the 'i' to the input of the 'replace subset array icon' , but i'm unable to do it as i got some error.
    Please help me!
    For your information, I'm using LABView 7.0.

    Hi,
    Thanks for your reply.Sorry for the confusion.
    I manage to change the array element by changing the row and column value. But, what i want is to allow the program to change the array element at a specified row and column value, where the new value is generated automatically by the program.
    Atatched is the diagram. I've detailed out the program . you may refer to the comments in the formula node. There are 2 arrays going into the loop. If a >3, then the program will switch to b, where if b =0, then the program will check on the value of the next element which is in the same row with b but in the next column. But if b =45, another set of checking will be done at a dufferent value of row and column.
    I hope that I have made the problem clear. Sorry if it is still confusing.
    Hope you can help me. Thank you!!!!
    Attachments:
    arrayrowncolumn2.JPG ‏64 KB

  • How to insert a new line in MC1H(maintaining formula)

    How to insert a new line in MC1H(maintaining formula)
    Can anybody help me with  the steps

    Hi,
    1.run transaction SCC4 -> press Ctrl+F4 or the button for change ->double click one the row for your client -> on the field Cross Client Object Changes select Changes to the Repository and cross-client Customizing allowed -> SAVE
    2. run MC1H and now you will have access to insert new line in the table
    Regards Vassko!
    Edited by: Vasil Pavlov on Sep 16, 2008 9:51 AM

  • How to insert the new field to standard scheduling agreement script form.

    Hi Gurus,
    how to insert the new fields to standad sheduling agreement script form. its a need for me, i want to display the AEDAT field in scheduling agreement form ,
    The below one is my requirement,
    ex:-   Itu2019s requested the change of Scheduling Agreement printout. Itu2019s requested for this type of   document, the insertion, into the field u201CData Emissionu201D into the print, of the document last modify date instead of the document creation date. (This change will be done only for position change into the Scheduling Agreement). No change into the PO.
    Change SAPSCRIPT printout. Introduction, into the Scheduling Agreement, of last modified  
          document date (field EKPO-AEDAT).
    Thanks & Regards
    chinnu

    open TNAPR table and give the output type you need to modify.... get the print program name and check if some structure already have the date you wanted... if you have it already... then open the form in SE71 tr. and provide the strcuture name - feild in the position you want to have the date...
    se71--->
    &<str. name>-AEDAT&

  • How to create a new field for Q3 - QM notification in Header and item level

    Dear All,
    l
               Sub: How to create a new field for Q3 - QM notification in Header and item level
    Ref. the link --> Quality Notification
    We want to create a new field in header level and item level.
    As per the thread the solution is given below.
    In the IMG Config: Quality Management -> Quality Notification -> Notification Types -> Define screen areas for notification types Then Choose 'Define screen areas' Then Click on 'New entries' button Now, select the relevant Notification Type and click in 'Enter'. Select the 'Iten Cases' register and remember to setup the Tabstrip Header, Icon, etc. Set the 'Tabstrip active' flag. Then Save.
    Quality Notification -> Notification Types -> Define screen areas for notification types
    WE ARE UNABLE TO FIND IN CUSTOMIZATION PATH --> DEFINE SCREEN AREAS FOR NOTIFICATION TYPES.
    Please help.
    Question No. 2 :
    THE REQUIREMENT IS GIVEN BELOW.
    We want to hide the field in Q3 - QM Notification
    In header --> Reference tab --> Item (sub heading) --> "DEFECT LOCATION" FIELD TO BE ELIMINATED (HIDE)
    Ref the link --> Quality notification
    The solutiion is given below.
    Hi Sami,
    We can hide the collumns using the Transaction OQM1 and Program Name SAPLIQS0.
    Lets say Defect location need to be hidden, the field TXTCDOT need to have the radio button HIDE.
    Hope this will suffice your requirement.
    Kindly ask me if you need any other details.
    Thanks & Regards,
    Srinivas.D
    Hi Sami,
    We can hide the collumns using the Transaction OQM1 and Program Name SAPLIQS0.
    Lets say Defect location need to be hidden, the field TXTCDOT need to have the radio button HIDE.
    Hope this will suffice your requirement.
    Kindly ask me if you need any other details.
    Thanks & Regards,
    Srinivas.D
    By double clicking the "DEFECTIVE QUANTITY (EXTERNAL), WE COULD NOT GET --> field TXTCDOT .
    Plese do the needful.
    We are using ECC6.0 Ehp3 and Ehp4.
    With Best Regards,
    Raghu Sharma

    Dear Pushpa,
    Transaction Code :SHD0 is working fine.
    Please accept my sincere thanks for your sharing your Knowledge.
    I am able to fulfill my
    Regarding the enhancement, I have not tried.
    Once I will complete, I will award the fulll marks to you.
    With Best Regards,
    Raghu Sharma

  • How to add a new tab for the project?

    Dear All Experts,
        Could you tell me how to add a new tab for the project?
        Pls refer to the screenshot as below:
    Thanks!
    Xinling Zhang

    Hi,
        The new tab in cj20n , and the new tab can only be displayed in the highed level.Pls refer to below
        And in cj02, there is no this tab also in the wbs detailed screen,
    Thanks!
    Xinling

  • How to create a new Condition for tax as VAT ( 4 % )  in SAP ? .

    Dear All ,
                           Pl guide that " How to create a new Condition for tax as VAT ( 4 % )  in SAP ? . What are all necessary requirements to do so , I need to have all steps so that i should feel very confident . For example what data is to be ticked in Control tab during cond. creation , in the same way how to put this cond. in Pricing procedure ? pl write all necessary thing which are required during this process .
    Thanx & deep regrads to all in adv.
    sap11

    In tax we can configure taxprocedure two types i.e., taxinn and tainj. If you adopt taxinn procedure if  it is other than VAT condition first you have to create the condition type and then you have to go to FTXP and assign the tax required VAT percentage to the repective % to ded or non ded VAT condion type. In second step you have to assign this tax code to respective company code.
    If you adopt taxinj procedure you have to a create tax code with FTXP T-code by assigning the values to the respective and save conditions.
    Regards,
    Bhuvan

  • How to set a new value for formula field in crystal reports xi?

    <p>How to set a new value for formula field in crystal reports xi?</p><p>//formula</p><p>{@description}</p><p> </p><p>exemplo in VB6</p><p>crxSubreport.FormulaFields.Item(1).Text =  "&#39;Subreport Formula&#39;"  or</p><p>crxSubreport.FormulaFields.Item("description").Text =  "&#39;Subreport Formula&#39;"</p><p>How to in JRC?</p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p>

    Hi,
    This functionality is known to be very important and is a key part of the next major release of the JRC planned for the first half of 2008.
    Regards,
    <p>Blair Wheadon</p>
    <p>Product Manager, Crystal Reports</p>

  • How to save a new value for Set command variable

    I am using SET [variable = [String]] to update Set variable. It works fine. But when I restart MSDOS Prompt, I get old value for variable.
    How to save a new value for SET command variable?
    I am using Windows XP.

    And this has to do with java how?

  • How much is a new screen for a mac book pro

    how much is a new screen for a mac book pro? - mine is cracked and shattered, everything else seems to work at mo?

    check this link ifixit.com

  • Hi All ,How to add a new  field for MEDRUCK if we havea ZMEDRUCK

    Hi All ,
            How to add a new  field for MEDRUCK if we have a ZMEDRUCK
    Req: If I want to add a new field for the following text editor line :
    IN MAIN WINDOW > TEXT EDITOR> SERCH FOR TOTAL_AMOUNT-->
    In that we will have
    &ekko-waers&    &komkfkwrt&
    (currency)       (numerics)
    Pls send the Code to make these changes .Pls its urgent
    Thanks&Regards.
    Bharat.

    Hi
    If that field which you wants to add is available in one of the structures like EKKO,EKPO then you can add that field just beside the other fields
    If that field is not there in the any of the structures then you can define a variable using define command
    /: DEFINE  &VAR&
    / &VAR&  = <some value>
    or you can write subroutines to fetch the data from outside tables and can use those fields data in the script
    <b>Reward points for useful Answers</b>
    Regards
    Anji

  • How to Insert a new line in a clob

    hi,
    i want to create reports as multi-line clob data using PL/SQL procedures.
    is there any standard way of inserting a new line when iam generating
    this clob data based on the data i fetch from a different table.
    i short my question is "How to insert a new line in a clob?"
    i tried using the character '\n', but that was of no use.
    thanks in advance
    ramesh

    You could always do a:
    newLine := '
    Since PL/SQL allows a tring to span multiple lines.

  • Hello. I just know the muse and I need an organization of customers in alphabetical order. The problem is that you will always get new customers. I need to know how to insert a new customer (square) and it already comes in alphabetical order on the page.

    Hello.
    I just know the muse and I need an organization of customers in alphabetical order. The problem is that you will always get new customers. I need to know how to insert a new customer (square) and it already comes in alphabetical order on the page. The site will be like in the link below, and each client will be a window of these: http://www.connary.com/. I look back.
    A hug, Murilo.

    I believe you are referring to thumbnail image rectangles as customers on page ? not exactly customer database ?
    You can add rectangle with different effects with mouse rollover state and regarding adding new ones , you would need to do that manually in design mode .
    Thanks,
    Sanjit

Maybe you are looking for

  • Handling Error Message in BADI BEFORE_TRIP_SETTLEMT

    Hi All, We have implemented BADI BEFORE_TRIP_SETTLEMT. As can be seen, there are no exceptions for the only method CHANGE_TRV_RULES. However, we have to throw error message on some condition. We wrote: MESSAGE 'Error' TYPE 'E'. This is taking the con

  • Export crashing in 1.0

    Well, its better than Beta 4.1 when I would crash just trying to access the Library. At least now I can open an image and develop it, but its pretty useless to me if I cannot Export. XP Pro;SP2, P4, 2g ram, ATI 8600 video w/ latest drivers installed.

  • HTTP getURLName

    I am trying to find a way in java to accept an HTTP post method and get the URL name from the method. I have had no luck finding any params that fit this need. If anyone has any ideas of how to grab that info from a request please respond. Thank you

  • Creating class files

    javac.exe is not creating class file.My os is win2000 and system 1s PIV

  • Web Problem (Urgent)

    Hi, I have created a form and running it (from Run a Form on the Web) on the web. it works well when I run this from from NT Server or NT Workstation. It kills the machine when I run this from from Windows 95/98 machine. Does any body know why this i