Get Old Value and the new value based on the date

Hi
I have a table called roster created below with following insert statements.
CREATE TABLE ROSTER
ROSTER_EMPLOYEE_DEF_ID NUMBER,
EMPLOYEE_ID NUMBER,
DEFINITION_REGION_CODE NUMBER,
DEFINITION_DISTRICT_CODE NUMBER,
DEFINITION_TERRITORY_CODE NUMBER,
START_DATE DATE,
END_DATE DATE
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(1,299,222,333,444,'1-JUN-2011','30-JUN-2011')
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(2,299,223,334,445,'1-JUL-2011','20-JUL-2011')
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(3,299,224,335,446,'1-AUG-2011','30-AUG-2011')
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(4,300,500,400,300,'1-JUN-2011','20-JUN-2011')
INSERT INTO ROSTER
(ROSTER_EMPLOYEE_DEF_ID,EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE)
VALUES
(5,300,501,401,301,'1-JUL-2011','20-JUL-2011')
In the above table we have columns like
EMPLOYEE_ID,DEFINITION_REGION_CODE,DEFINITION_DISTRICT_CODE,DEFINITION_TERRITORY_CODE,START_DATE,END_DATE
The result i am looking from the above table is based on the EMPLOYEE_ID OF START_DATE AND END_DATE
I need to get OLD_DEFINITION_REGION_CODE and the NEW_DEFINITION_CODE
Similarly OLD_DEFINITION_REGION_CODE and the NEW_DEFINITION_REGION_CODE
and OLD_DEFINITION_TERRITORY_CODE and the NEW_DEFINITION_TERRITORY_CODE
I need to get one row of data for each employee saying old value and new value
for employee 299 there are 3 records it must give the new record which is the latest date i.e start date 1-aug-2011 and end date 30-aug-2011 old record will be
start date 1-jul-2011 and 20-jul-2011
For the above table data i need to get the data as below
EMPLOYEE_ID OLD_DEFINITION_REGION_CODE NEW_DEFINITION_CODE OLD_DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE START_DATE END_DATE
299 223 224 334 335 20-JUL-11 30-AUG-11
300 500 501 400 401 20-JUN-11 20-JUL-11
Please suggest me to get the above result based on the data. Please let me know if my posts are not clear
Thanks
Sudhir

SELECT  EMPLOYEE_ID,
        OLD_DEFINITION_REGION_CODE,
        NEW_DEFINITION_REGION_CODE,
        OLD_DEFINITION_DISTRICT_CODE,
        NEW_DEFINITION_DISTRICT_CODE,
        OLD_DEFINITION_TERRITORY_CODE,
        NEW_DEFINITION_TERRITORY_CODE,
        START_DATE,
        END_DATE
  FROM  (
         SELECT  EMPLOYEE_ID,
                 ROW_NUMBER() OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE DESC) RN,
                 LAG(DEFINITION_REGION_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_REGION_CODE,
                 DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE,
                 LAG(DEFINITION_DISTRICT_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_DISTRICT_CODE,
                 DEFINITION_DISTRICT_CODE NEW_DEFINITION_DISTRICT_CODE,
                 LAG(DEFINITION_TERRITORY_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_TERRITORY_CODE,
                 DEFINITION_TERRITORY_CODE NEW_DEFINITION_TERRITORY_CODE,
                 LAG(END_DATE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) START_DATE,
                 END_DATE
           FROM  ROSTER
  WHERE RN = 1
EMPLOYEE_ID OLD_DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE OLD_DEFINITION_DISTRICT_CODE NEW_DEFINITION_DISTRICT_CODE OLD_DEFINITION_TERRITORY_CODE NEW_DEFINITION_TERRITORY_CODE START_DAT END_DATE
        299                        223                        224                          334                          335                           445                           446 20-JUL-11 30-AUG-11
        300                        500                        501                          400                          401                           300                           301 20-JUN-11 20-JUL-11
SQL>  SY.

Similar Messages

  • Retrieve data from a text file, incrementing the last value and save new value below

    Hi
    This was working initially. It is part of my LabView Project. I was trying to create a unique number that increments every time the adds the value to the list. It works on computer perfectly. But when I put this on a PDA, it seems to create a blank space when reading the contents of the text file after the last value, which means 0 + 1, which is not what I want.
    Please run the testUniqueNoOnPDA.vi first and change the path to C:\uniqueNumber.txt and save the uniqueNumber.txt file to your C drive and see What I am trying to do. Click the Enter button to increment.
    Why does the PDA create a blank space after the last value and a computer does not?
    I was working perfectly all week and it is not working well now.
    Help please, I think I'm missing something
    Attachments:
    uniqueNumber.txt ‏1 KB
    testUniqueNoOnPDA.vi ‏33 KB
    testUniqueNoOnPDA.lvproj ‏4 KB

    It works perfectly, it was a hardware problem. It depends on what PDA I used.

  • Highlight an address on a web page and make new card based on the address?

    Is there a way to highlight an address in another application, and then create a new card based on that address, where city, state, phone number, etc would all be parsed into the separate fields automagically?

    As per the title really - anyone know of a method of including an email address on a web page without it being picked up by spam bots?
    Impossible.
    Usually if i want to avoid that, I just do a little form with a honey trap, but I'm working on a page that needs contact details for around 100 places, so doing 100 odd forms for a single page might be a little impractical....
    Run it inside a script that parses an XML file based on the link's ID - one script, many links, no directly visible mail addresses (though, of course bots can still parse the XML file itself, if not in a hidden directory or something liek that).
    Mylenium

  • Creation of a new record based on the value of a picklist

    Hi,
    My requirement is whenever i select a picklist value in Opportunity record type based on the value selected a new opprtunity record should get created and get assigned to a role or A User otherwise a lead should get created and should be assigned to a Role or A User.
    Can I achieve this in OnDemand?
    Kindly help. This is urgent..
    Thanks in Advance.

    Can I achieve this in OnDemand?I think you can better try one of the Oracle CRM On Demand forums @ http://forums.oracle.com/forums/category.jspa?categoryID=162
    instead of the Oracle SQL and PL/SQL forum.
    This is urgent..The forums are relying on volunteers and it is weekend for most of us now.
    If it is really that urgent, call Oracle Support.

  • Spark datagrid that shows the new  value and that it previously was

    Im trying to create a item renderer for a spark datagrid that shows the new  value and that it previously was and I am comparing in the set data, the problem I am having is that in teh set data I am frequently getting data from other rows (I know this because of virtual renderders), it there a way round this?
    <?xml version="1.0" encoding="utf-8"?>
    <s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                        xmlns:s="library://ns.adobe.com/flex/spark"
                        xmlns:mx="library://ns.adobe.com/flex/mx"
                        currentState="unmodified">
        <fx:Script>
            <![CDATA[
                override public function set data(value:Object):void
                    if(data){
                        if(super.data.margin != value.margin  && super.data.margin){
                            oldValue.text = '(' + super.data.margin + ')';
                        }else{
                            oldValue.text == '';
                    super.data = value;
                    stroke.visible = false;
                    fillRect.visible = false;
                    if(data){
                        if(this.data.isModifiedClientSide){
                            currentState = "modified";
                            fill.color = 0xddddff;
                            stroke.visible = true;
                            fillRect.visible = true;
                        else{
                            fill.color = 0xffffff;
                            stroke.visible = false;
                            currentState = "unmodified";
                            fillRect.visible = true;
            ]]>
        </fx:Script>
        <s:states>
            <s:State name="modified"/>
            <s:State name="unmodified"/>
        </s:states>
        <s:Rect top="0" left="0" right="0" bottom="0" id="fillRect" >
            <s:fill><s:SolidColor id="fill"  color="0xFFffff"  /></s:fill>
        </s:Rect>
        <s:Rect left="1" top="1" right="0" bottom="0" id="stroke">
            <s:stroke >
                <s:SolidColorStroke color="0x000099" weight="1"  >
                </s:SolidColorStroke>
            </s:stroke>
        </s:Rect>
        <s:HGroup horizontalAlign="center" verticalAlign="middle" top="0" left="0" right="0" bottom="0" paddingRight="5">
            <s:Label text="{data.margin}" width="50%" textAlign="right">
            </s:Label>
            <s:Label  id="oldValue" color="0xff0000" width="50%"  textAlign="right">
            </s:Label>
        </s:HGroup>
    </s:GridItemRenderer>

    If I recall correctly, you are talking about the default start page. To check if this is correct, type '''about:home''' in the awesome bar. If this is the same as your homepage, it will still be there when you update.

  • Get the new value from an event structure block

    Hello!
    I'm using an event structure block. I've edited an event wich its event sources are an indicator an a variable (a real matrix). I want to get (to catch) the new value of the indicator and the variable from the frame placed at the left top, but the new value attribute is not a real not an integer.....is variant type. I have no idea what i have to do to catch this two values from here. Someone can post a simple example about it?
    Thanks in advance!
    Regards
    Larson 

    If the terminal is INSIDE the event structure, you'll always get the new value. It will NOT be read until the event case executes, at which point the terminal contains the new value. (If the terminal is outside the event structure, and the wire goes inside the event structure, you'll get a stale value when the event for that terminal triggers. This is expected from the dataflow.)
    Put the terminals inside the proper event case, you'll be fine!
    LabVIEW Champion . Do more with less code and in less time .

  • How to set a default value for a drop down list box and then apply cascading based on the default value in Infopath 2010.

    Hello Everyone
    I have two drop downs. Both are coming from look up fields from two lists. i want to set a default value(first list item) for the first drop down list box and then apply cascading based on the default value for the next drop down list box. I found one article(http://www.bizsupportonline.net/infopath2010/display-first-item-drop-down-list-box-infopath-2010.htm)
    where in i can set a default value but i can't apply cascading based on that default value. Any suggestions would be highly appreciated.
    Thanks
    Ramanjulu Naidu N

    Hey Ramanjulu,
    Take a look at the below article which I believe will answer your question.
    http://basquang.wordpress.com/2010/03/29/cascading-drop-down-list-in-sharepoint-2010-using-infopath-2010/
    Daniel Christian (MCTS)

  • I just purchased a new computer and downloaded I tunes but when I go to sync my iphone and ipad touch my library from my old computer doesn't show up on the new one. Only the purchased itumr dongs come up. How do I get my original itunes library?

    I just purchased a new computer and downloaded I tunes but when I go to sync my iphone and ipad touch my library from my old computer doesn't show up on the new one. Only the purchased itune songs come up. How do I get my original itunes library?

    Have you copied your content over from your old computer and onto the new on ? If not, and you still have your old computer, then there a number of methods described on this page which you can use to copy your library over : http://support.apple.com/kb/HT4527 . If you no longer have your old computer then have you got a backup of your content that you can copy onto the new computer and add into iTunes ?

  • I have my my original itunes on my old computer that doesnt accept CD's anymore. My new computer has some of the old songs and some new songs. How do I get all my old content on the new computer and still keep the new content?

    I have my my original itunes on my old computer that doesnt accept CD's anymore and My new computer has some of the old songs and some new songs. How do I get all my old content on the new computer and still keep the new content? I also have a few different ipods and I want to have all the songs on all of them but it wont let me. I have read millions of the help articles and still cant figure it out. When I plug one ipod in it says it is going to delete all the old info to sync and cant just add the songs? Frustrated please help!!

    Copy everything from the old computer or your backup copy of your old computer, to your new one.

  • Enable the field in the list display and insert the new value and  save it.

    Hi
    In a report when I am in third list using ALV a field which is disabled should be enabled and  have to insert the new value in it and  save.
    please tell me how to do it using classes and methods and also using ALV's.
    Promise to reward points.
    Regards
    Mac

    Hi madan,
    Please find the code sample,
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/79b5e890-0201-0010-7f8e-b7c207edf7c2
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/ec31e990-0201-0010-f4b6-c02d876ce033
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/117beb90-0201-0010-67a8-fff1482209ae
    Regards
    Kathirvel

  • I am working in Numbers and can't seem to change the generic value assigned to the legend.  Any advice on how to select the legend and save new values?

    I am working in Numbers and can't seem to change the generic value assigned to the legend.  Any advice on how to select the legend and save new values?

    Ntenich,
    If your table has a Header and your Legend text is in the header, it will be picked up by the table.
    Jerry

  • I was transferring my information from my old iphone to the new one, and i forgot that i had some pictures in the new one. i did the restoring information and the pictures in new one are gone. how can i get them back????

    i was transferring my information from my old iphone to the new one, and i forgot that i had some pictures in the new one. i did the restoring information and the pictures in new one are gone. how can i get them back???? please

    Only way to get it back is to restore your phone from a backup, if those pics were included in that backup.
    But most likely those pics are gone.
    What you should've done was import http://support.apple.com/kb/HT4083 the pics to your computer and after you restored from your old backup, you could sync those new pics to your phone via itunes.

  • Wenn I've made changes on my private home-page and want to see the result, how do I get my Mac to load the new side instead of the "old" one?

    When I've worked on my private home-page and want to controll the results, how do I get my Mac to take the new version instead of the old one? I tried cmd R without any change! Who knows? Nina

    Try clearing the cache - command-option-e in Safari.

  • My old computer that ran on Mavericks was stolen and my new computer runs on Yosemite. I don't like the new iMovie (10) on the Yosemite version. Is there any way to get the old version (9) back?

    My old computer that ran on Mavericks was stolen and my new computer runs on Yosemite. I don't like the new iMovie (10) on the Yosemite version. Is there any way to get the old version (9) back?

    I read his question the way I answered it.
    If that is wrong then he can clarify his question.

  • HT5622 iPhone is stuck on old ID and won't let me change the ID to get into Cloud segment of Settings.  Need to get this straight so I can backup to Cloud before updating to new System

    iPhone is stuck on old ID and won't let me change the ID in settings to get into Cloud.  Want to sync phone to Cloud before updating the Systems.  No such problem on other phone or 2 iPads linked to account.  Help!

    Thanks Bob,
    That was just a typo.
    I have three accounts set up in Mail, one of which, apart my the username which is my son's, has exactly the same settings as the one that isn't working and remember it's affecting all my devices.
    I would feel happier even if I could create a fourth account on my MacBook Pro using what I know to be the correct password for the server but when I try it keeps defaulting to imap type, I don't get an option for Pop which is what I need.
    Oh Bum.
    K

Maybe you are looking for

  • Delayed save as dialog box.

    I have an issue with any adobe product that I have on my machine. Illustrator, Framework, or photoshop. Whenever I go to save as, it is always delayed at least 10 seconds or longer. I have checked network drives that are no longer available, network

  • Read content of email type MHT

    Hello all, I have a small problem to read content of incoming emails in SO , where OBJ_TYPE = 'MHT'. Using FM SO_DOCUMENT_READ_API1 I get content of email in table  OBJECT_CONTENT, and after conversion I have text like this: "Content-Type: multipart/

  • Matrix x System Form x UDO

    Hey all, I´m asking for some help to deal with the following: I want to show a new Matrix in a System Form.  The data is from a UDO (line data - detail). How should i do that ?  Can i use UDO methods ? Anyone can help me ?

  • Problem with Body of the main window

    Hi friends, While Printing the smart form the main window body is not reaching to the end of the main window dimensions.(There is no footer for the main window). Its Printing all the records and at the end its giving one line gap. My problem is the v

  • How to avoid BPEL process deployment after server restart

    Hi, Message flow in my application is as below BPEL1 --> ESB --> BPEL2 After every server restart the ESB is failing to invoke a perticular operation of BPEL2 service. All other operations of BPEL2 are working fine. We are redeploying the BPEL2 procc