conditional merge based on the date

Need help on a merge statement. I need to merge two dataset. But when the key match, I also need to cpmpared the date before I merege it.
See code below
drop table x1;

drop table y1;

select * from x1;

select * from y1;

create table x1 (id number,name varchar2(10),cdate date,status varchar2(1));

create table y1 (id number,name varchar2(10),cdate date,status varchar2(1));

insert into x1 select 1,'A',sysdate - 100,'Y' from dual;

insert into y1 select 1,'A',sysdate - 50,'N'  from dual ;--should change x1.status to y1.status  and x1.cdate to y1.cdate as y1.cdate > x1.cdate

insert into x1 select 2,'B',sysdate - 20,'Y' from dual;

insert into y1 select 2,'B',sysdate - 120,'N' from dual ;--should leave status in x1 alone

insert into y1 select 3,'c',sysdate - 10,'Y' from dual; --should do an insert on x1 

commit;

--how do I do a conditional merge (key=id,name)
-- based on the cdate. If y1.cdate >= x1.cdate then take the y1.status  and y1.cdate

--desire output
select * from x1
1     A     01/01/2012 10:54:35 AM     N
2     B     1/31/2012 10:54:37 AM     Y
3     C     1/31/2012 10:54:37 AM     Y

Hello

You can add a WHERE clause to the WHEN MATCHED THEN UPDATE section.

WHERE   x1.cdate  < y1.cdate

Thanks for posting the CREATE TABLE and INSERT statements; It is very useful. It would also help if you have validated your MERGE statement, even if it does not work perfectly.

Tags: Database

Similar Questions

  • How to hide/show a field based on the data from more than 1 field?

    Hello.

    I'm trying to hide/show a based on the data of field2 and field3, Field1

    in fact using dynamic measurements I can only hide/show Field1 Field2-based, but I need a combination, for example:

    If field1 = 'A' and field2 = 'B', then see the field3, other hide field3

    y at - it an easy way to do it.

    I use Application Express 4.2.4.00.08

    Thanks in advance

    Dynamic action

    On the changes

    jQuery selector: #P1_ITEM_1, #P1_ITEM_2

    Condition: JavaScript

    $v ('P1_ITEM_1') == 'A' & $v ('P1_ITEM_2') == 'B '.

    Real Action: show item 3

    Action of false: hide item 3

  • How to plan the report filtered by dynamic date based on the date, the Agent is running

    Hello

    I have a question about account using OBIEE agent.

    If I run an agent today to deliver A report, can I me A report based on the date of last Monday or any dynamic dates?

    For example, say is today, December 18, 2013, and my agent is run according to how I put the calendar. Now the content of the delivery report one being delivered. Now A report has a date column, normally this column is filtered by the current date. But if it comes through the agents to different users, the data should be the previous Monday, so in this case, 9 December 2013. When this agent is run once again, declared December 27, 2013, then the report must be filtered by December 16, 2013, which is the previous Monday 27 dec.

    Something like this is possible in OBIEE 11 G?

    Thanks in advance.

    Yala,

    Not in a straightforward way

    (1) let the report through Agent with filter current Date

    (2) after he ran for the first time you can see IBOT name/last execution time (LAST_RUNTIME_TS) in S_NQ_JOB

    Create a variable reference 'last_run_agent' to aid in sql to get max (LAST_RUNTIME_TS)

    SELECT max (LAST_RUNTIME_TS) from s_nq_job, whose name = "AGENT_NAME;

    Change analysis with current date filter report and amend accordingly the condition of filter to filter on repository variable, newly created

    Thank you

    Angelique

  • Find (weekly) missing date ranges based on the Date of submission

    Nice day:

    I have a table that contains the data with a date of presentation of the report column.  If the requirements are that each employee must submit at least 1 weekly report beginning January 1, 2015, how can I find the weekly reports missing, based on the date of submission of reports.

    The ideas that I had:

    • Left join by partition by date (range between)
    • Create a date dimension view?

    Of course, I'm not sure how to approach this dilemma without creating a query of Monster.  Sometimes the simplest queries mistake me...

    Thank you, Aqua

    Here are the DDL for the table with the information from the presentation report (example):

    --------------------------------------------------------

    -The DOF for Table DTS_FORM_SAMPLE

    --------------------------------------------------------

    CREATE TABLE 'DTS_FORM_SAMPLE '.

    (NUMBER OF 'ID',

    VARCHAR2 (20) "CLOCK_NUMBER."

    NUMBER OF 'EMP_ID,'

    NUMBER OF "REPORT_TYPE."

    DATE OF THE "SUB_DATE.

    ) ;

    /

    INSERTION of REM in DTS_FORM_SAMPLE

    TOGETHER TO DEFINE

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2896, 'XX2444', 12810,1, to_date('02-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2897, 'XX2444', 12810,1, to_date('09-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2898, 'XX2444', 12810,1, to_date('16-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2899, 'XX2444', 12810,1, to_date('23-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2900, 'XX2444', 12810,1, to_date('30-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2901, 'XX2444', 12810,1, to_date('05-MAR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2902, 'XX2444', 12810,1, to_date('12-MAR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2903, 'XX2444', 12810,1, to_date('19-MAR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2904, 'XX2444', 12810,1, to_date('26-MAR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2920, 'XX2444', 12810,1, to_date('19-FEB-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2921, 'XX2444', 12810,1, to_date('22-JAN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2922, 'XX2444', 12810,1, to_date('05-FEB-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2923, 'XX2444', 12810,1, to_date('26-FEB-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2924, 'XX2444', 12810,1, to_date('29-JAN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2925, 'XX2444', 12810,1, to_date('12-FEB-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (2965, 'XX2444', 12810,1, to_date('30-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6970, 'XX2444', 12810,1, to_date('18-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6971, 'XX2444', 12810,1, to_date('25-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6972, 'XX2444', 12810,1, to_date('04-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6973, 'XX2444', 12810,1, to_date('11-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6978, 'XX2444', 12810,1, to_date('14-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6979, 'XX2444', 12810,1, to_date('21-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6980, 'XX2444', 12810,1, to_date('28-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6981, 'XX2444', 12810,1, to_date('07-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6948, 'XX2444', 12810,1, to_date('06-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6957, 'XX2444', 12810,1, to_date('09-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6958, 'XX2444', 12810,1, to_date('16-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6959, 'XX2444', 12810,1, to_date('23-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6960, 'XX2444', 12810,1, to_date('02-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8938, 'XX2444', 12810,1, to_date('14-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8939, 'XX2444', 12810,1, to_date('21-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8940, 'XX2444', 12810,1, to_date('28-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8941, 'XX2444', 12810,1, to_date('07-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8942, 'XX2444', 12810,1, to_date('14-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8943, 'XX2444', 12810,1, to_date('21-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8977, 'XX2444', 12810,1, to_date('04-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8978, 'XX2444', 12810,1, to_date('11-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8979, 'XX2444', 12810,1, to_date('11-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8980, 'XX2444', 12810,1, to_date('18-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8981, 'XX2444', 12810,1, to_date('18-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8982, 'XX2444', 12810,1, to_date('25-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8983, 'XX2444', 12810,1, to_date('25-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8984, 'XX2444', 12810,1, to_date('02-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8985, 'XX2444', 12810,1, to_date('02-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8953, 'XX2444', 12810,1, to_date('19-FEB-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9824, 'XX2444', 12810,1, to_date('20-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9825, 'XX2444', 12810,1, to_date('20-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9826, 'XX2444', 12810,1, to_date('20-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8972, 'XX2444', 12810,1, to_date('30-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8973, 'XX2444', 12810,1, to_date('30-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8974, 'XX2444', 12810,1, to_date('07-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8975, 'XX2444', 12810,1, to_date('28-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8951, 'XX2444', 12810,1, to_date('12-FEB-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8952, 'XX2444', 12810,1, to_date('19-FEB-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8954, 'XX2444', 12810,1, to_date('26-FEB-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8955, 'XX2444', 12810,1, to_date('26-FEB-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8956, 'XX2444', 12810,1, to_date('05-MAR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8957, 'XX2444', 12810,1, to_date('05-MAR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8958, 'XX2444', 12810,1, to_date('12-MAR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8959, 'XX2444', 12810,1, to_date('12-MAR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8960, 'XX2444', 12810,1, to_date('19-MAR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8961, 'XX2444', 12810,1, to_date('19-MAR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8962, 'XX2444', 12810,1, to_date('26-MAR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8963, 'XX2444', 12810,1, to_date('26-MAR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8964, 'XX2444', 12810,1, to_date('02-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8965, 'XX2444', 12810,1, to_date('02-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8966, 'XX2444', 12810,1, to_date('09-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8967, 'XX2444', 12810,1, to_date('09-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8968, 'XX2444', 12810,1, to_date('16-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8969, 'XX2444', 12810,1, to_date('16-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8970, 'XX2444', 12810,1, to_date('23-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8971, 'XX2444', 12810,1, to_date('23-APR-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8976, 'XX2444', 12810,1, to_date('04-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8986, 'XX2444', 12810,1, to_date('09-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8987, 'XX2444', 12810,1, to_date('09-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9041, 'XX2444', 12810,1, to_date('16-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9042, 'XX2444', 12810,1, to_date('16-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9043, 'XX2444', 12810,1, to_date('23-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9044, 'XX2444', 12810,1, to_date('23-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9045, 'XX2444', 12810,1, to_date('30-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9046, 'XX2444', 12810,1, to_date('30-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9047, 'XX2444', 12810,1, to_date('06-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9048, 'XX2444', 12810,1, to_date('06-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8944, 'XX2444', 12810,1, to_date('22-JAN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8945, 'XX2444', 12810,1, to_date('22-JAN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8946, 'XX2444', 12810,1, to_date('29-JAN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8947, 'XX2444', 12810,1, to_date('29-JAN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8948, 'XX2444', 12810,1, to_date('05-FEB-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8949, 'XX2444', 12810,1, to_date('05-FEB-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (8950, 'XX2444', 12810,1, to_date('12-FEB-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9527, 'XX2444', 12810,1, to_date('13-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9528, 'XX2444', 12810,1, to_date('13-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (9529, 'XX2444', 12810,1, to_date('13-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6739, 'YY7223', 11093,8, to_date('15-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6740, 'YY7223', 11093,8, to_date('21-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6741, 'YY7223', 11093,8, to_date('22-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6742, 'YY7223', 11093,8, to_date('25-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6743, 'YY7223', 11093,8, to_date('26-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6744, 'YY7223', 11093,8, to_date('27-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6745, 'YY7223', 11093,1, to_date('04-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6746, 'YY7223', 11093,1, to_date('11-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6747, 'YY7223', 11093,1, to_date('18-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6748, 'YY7223', 11093,1, to_date('25-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6749, 'YY7223', 11093,11, to_date('01-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6750, 'YY7223', 11093,11, to_date('15-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (6751, 'YY7223', 11093,10, to_date('01-JUL-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (11017, 'YY7223', 11093,1, to_date('07-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (11018, 'YY7223', 11093,1, to_date('14-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (11019, 'YY7223', 11093,1, to_date('21-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (11020, 'YY7223', 11093,1, to_date('28-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (11021, 'YY7223', 11093,1, to_date('04-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (11022, 'YY7223', 11093,1, to_date('11-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (11023, 'YY7223', 11093,1, to_date('18-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (11024, 'YY7223', 11093,1, to_date('25-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (11025, 'YY7223', 11093,10, to_date('31-MAY-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (11026, 'YY7223', 11093,10, to_date('30-JUN-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13115, 'YY7223', 11093,1, to_date('13-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13201, 'YY7223', 11093,1, to_date('20-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13287, 'YY7223', 11093,1, to_date('27-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13373, 'YY7223', 11093,10, to_date('08-SEP-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13489, 'YY7223', 11093,8, to_date('01-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13490, 'YY7223', 11093,8, to_date('02-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13491, 'YY7223', 11093,8, to_date('03-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13492, 'YY7223', 11093,8, to_date('04-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13493, 'YY7223', 11093,8, to_date('05-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13494, 'YY7223', 11093,8, to_date('06-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13495, 'YY7223', 11093,8, to_date('07-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13496, 'YY7223', 11093,8, to_date('08-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13497, 'YY7223', 11093,8, to_date('09-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13498, 'YY7223', 11093,8, to_date('10-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13499, 'YY7223', 11093,8, to_date('11-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13500, 'YY7223', 11093,8, to_date('12-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13501, 'YY7223', 11093,8, to_date('13-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13502, 'YY7223', 11093,8, to_date('14-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13503, 'YY7223', 11093,8, to_date('15-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13504, 'YY7223', 11093,8, to_date('16-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13505, 'YY7223', 11093,8, to_date('17-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13506, 'YY7223', 11093,8, to_date('18-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13507, 'YY7223', 11093,8, to_date('19-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13508, 'YY7223', 11093,8, to_date('20-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13509, 'YY7223', 11093,8, to_date('21-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13510, 'YY7223', 11093,8, to_date('22-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13511, 'YY7223', 11093,8, to_date('23-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13512, 'YY7223', 11093,8, to_date('24-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13513, 'YY7223', 11093,8, to_date('25-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13514, 'YY7223', 11093,8, to_date('26-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13515, 'YY7223', 11093,8, to_date('27-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13516, 'YY7223', 11093,8, to_date('28-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13517, 'YY7223', 11093,8, to_date('29-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13518, 'YY7223', 11093,8, to_date('30-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13519, 'YY7223', 11093,8, to_date('31-AUG-15','DD-MON-RR'));

    Insert into DTS_FORM_SAMPLE (ID, CLOCK_NUMBER, EMP_ID, REPORT_TYPE, SUB_DATE) values (13030, 'YY7223', 11093,1, to_date('06-AUG-15','DD-MON-RR'));

    --------------------------------------------------------

    -Table DTS_FORM_SAMPLE constraints

    --------------------------------------------------------

    CHANGE ALTER TABLE 'DTS_FORM_SAMPLE' ('ID' ENABLE NOT NULL);

    /

    Or more simple:

    Select emp_id, w.wk, to_char (wk, 'ww') x

    from (select trunc (date ' 2015-01-01' + 7 * (level - 1), 'ww') wk)

    of the double

    connect by level<=>

    ) o

    left outer join

    s dts_form_sample

    by (emp_id) partition

    We trunc (s.sub_date, 'ww') = w.wk

    where sub_date is null

    order to emp_id,

    x

    /

    EMP_ID WK X
    ---------- --------- --
    11093 1ST JANUARY 15 01
    11093 8 JANUARY 15 02
    11093 15 JANUARY 15 03
    11093 22 JANUARY 15 04
    11093 29 JANUARY 15 05
    11093 5 FEBRUARY 15 06
    11093 12 FEBRUARY 15 07
    11093 19 FEBRUARY 15 08
    11093 26 FEBRUARY 15 09
    11093 5 MARCH 15 10
    11093 12 MARCH 15 11

    EMP_ID WK X
    ---------- --------- --
    11093 19 MARCH 15 12
    11093 26 MARCH 15 13
    11093 2 APRIL 15 14
    11093 9 APRIL 15 15
    11093 16 APRIL 15 16
    11093 23 APRIL 15 17
    11093 30 APRIL 15 18
    11093 37 15 - SEP - 10
    17-SEVEN 11093.-15 38
    24-SEVEN 11093.-15 39
    11093 1 OCTOBER 15 40

    EMP_ID WK X
    ---------- --------- --
    11093 8 OCTOBER 15 41
    11093 15 OCTOBER 15 42
    11093 22 OCTOBER 15 43
    11093 29 OCTOBER 15 44
    11093 5 NOVEMBER 15 45
    11093 12 NOVEMBER 15 46
    11093 19 NOVEMBER 15 47
    11093 26 NOVEMBER 15 48
    11093 3 DECEMBER 15 49
    11093 10 DECEMBER 15 50
    11093 17 DECEMBER 15 51

    EMP_ID WK X
    ---------- --------- --
    11093 24 DECEMBER 15 52
    11093 31 DECEMBER 15 53
    12810 1ST JANUARY 15 01
    12810 8 JANUARY 15 02
    12810 15 JANUARY 15 03
    12810 27 AUGUST 15 35
    12810 15 - SEP - 03 36
    12810 37 15 - SEP - 10
    17-SEVEN 12810.-15 38
    24-SEVEN 12810.-15 39
    12810 1 OCTOBER 15 40

    EMP_ID WK X
    ---------- --------- --
    12810 8 OCTOBER 15 41
    12810 15 OCTOBER 15 42
    12810 22 OCTOBER 15 43
    12810 29 OCTOBER 15 44
    12810 5 NOVEMBER 15 45
    12810 12 NOVEMBER 15 46
    12810 19 NOVEMBER 15 47
    12810 26 NOVEMBER 15 48
    12810 3 DECEMBER 15 49
    12810 10 DECEMBER 15 50
    12810 17 DECEMBER 15 51

    EMP_ID WK X
    ---------- --------- --
    12810 24 DECEMBER 15 52
    12810 31 DECEMBER 15 53

    57 selected lines.

    SQL >

    However OP question must answer is start of week date.

    SY.

  • Get the old value and the new value based on the date

    Hello

    I have a table called list created below with the rest of the insert statements.

    CREATE TABLE ROSTER
    (
    NUMBER OF ROSTER_EMPLOYEE_DEF_ID
    NUMBER OF EMPLOYE_ID
    NUMBER OF DEFINITION_REGION_CODE
    NUMBER OF DEFINITION_DISTRICT_CODE
    NUMBER OF DEFINITION_TERRITORY_CODE
    START_DATE DATE,
    END_DATE DATE
    )



    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (1,299,222,333,444, 'JUNE 1, 2011', 30 JUNE 2011 "")

    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (2,299,223,334,445, "1 JULY 2011', JULY 20, 2011" "")

    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (3,299,224,335,446, 'AUGUST 1, 2011', AUGUST 30, 2011 "")

    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (4,300,500,400,300, 'JUNE 1, 2011', JUNE 20, 2011 "")

    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (5,300,501,401,301, "1 JULY 2011', JULY 20, 2011" "")


    In the table above we have columns like

    EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE

    The result I'm looking for the table above is based on the employe_id OF start_date AND end_date

    I need to get the 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 a row of data for each employee saying old value and the new value

    for the employee 299 there are 3 records he puts the new record which is the latest date is to say beginning August 1, 2011 and end date of recordings old 30 August 2011
    beginning July 1, 2011 and July 20, 2011


    For the data in the table above, I need to get the data as below


    EMPLOYE_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 JULY 11 30 AUG 11
    300 500 501 400 401 20 JUNE 11 JULY 20, 11


    Please suggest me to get the result above, based on the data. Please let me know if my messages are not clear


    Thank you
    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.

  • Creating primary key based on the Date

    Hi all
    I am trying to create a unique ID for each record, based on the date that the record is created. Example, if the folder is created today, I want to the key is 20101130XX where XX is a sequential list of numbers e.g. 01, 02, 03 etc... in the case where more than one person creates a record today.

    If 3 people created record yesterday their unique ID would be

    2010112900
    2010112901
    2010112902

    and then comes the midnight and someone creates a new record, that it would be

    2010113000

    This is intended to give each record with a unique ID that will be used to reference the ticket.

    We are already using the date format, but currently users have to manually enter the id and who can create errors such as 2011112900 when it should have been 2010112900 then instead of 2010 they put 2011

    I'm not sure how to create a trigger to generate this type of unique identification number and would appreciate any help

    Thanks in advance

    Wally

    Never said it was perfect, but then again, it is a rather sticky issue... Reset sequence work would be scheduled to run @ some point... You entered in tables past 24/7? I would say that system could be locked for those 5 minutes sequence is updated, or the table is locked to allow no access while the process is...

    To be honest, that is the question in the design of a key value that is dependent on outside data, as apposed to a surrogate key, which is generated System... Again, you could have at ONCE and have the surrogate for a key key REAL primary and date + sequence as a secondary key for the use of basic unit of carbon...

    Thank you

    Tony Miller
    Webster, TX

    If vegetable oil is made from vegetables, then what is baby oil?

  • Conditional formatting depends on the date ranges

    Basically, I want to be able to enter a date in column A and a sum of money in the B column, depending on where the date in column A grave in a date range, I want the money in column B to copy to a corresponding column. Is this possible? The only questions I found on here deal in a conditional formatting with dates have to do with derivative.

    Thank you

    Julio

    I hope this help to clarify for you...

    It is not bringing conditional formatting.  Formatting conditional would change the format of a cell (or cells)... as the font, color, size, color cell background, or other formatting character is tics of a cell based on the contents of the cell

    You ask about including of the value of a cel another beach under certain conditions

    Here is an example:

    The first three rows are header lines.

    You must enter a valid date for the towing job.  Using the format "mm/dd/yyyy".

    C4 = IF (AND (DATEVALUE (A4) ≥DATEVALUE($B$1), DATEVALUE (A4) ≤DATEVALUE($B$2)), B4, "")

    It's shorthand dethrone select cell C4, and type (or copy and paste it here) the formula:

    = IF (AND (DATEVALUE (A4) ≥DATEVALUE($B$1), DATEVALUE (A4) ≤DATEVALUE($B$2)), B4, "")

    Select the cell C4, copy

    Select cells C4 at the end of the C column, paste

  • The smart Albums based on the date range cause app Crash Photos

    While I'm setting up a new Smart Album based on day of photos between 12/01/2015 and 31/12/2015 the Photos app closes with a crash. Cannot set the second date (the end date for this album). However, I can easily create a new Smart Album for next month (01/01/2016 and 01/31/2016). I create smart Albums, because the new Photos app does not like the old iPhoto does with my Photos from the photo gallery.

    How can I solve this? I don't have an album of December...? !

    You are in an area where the date format is different from the United States?  Earlier this year, we have seen small business issues have reported that rules for smart albums date range do not work with the primary language set to French or German.

    Try to change the primary system language to English with an English date format. Photos could be trying to read the 12/31/2015 as the 12th day of the month 31.

    Or use a different date based on 'before' rule and after.

  • Then the validation of a detail or form based on the date picker - upper effective Date?

    Hi, creates a BP custom with the effective date in field added to my details form or higher. Can I have a set of validation rules up for my top of or the form detailed such as the effective date cannot be greater than the current date? Thanks in advance.

    For the decimal amount, you need to change the formula type, the default value is a numerical formula, but you must choose the date difference. This is the online help:

    To create a date-difference formula

    1. Open the form that contains the field for which you want to create a formula. The form designer window opens.
    2. In the form designer window, select the date field that you want to create the formula. When the calculation is performed, this field appears as read-only on the form and will automatically update each time that the fields that make up the formula change.
    3. Click the formula button. A creation of the formula window opens.
    4. In the formula field Type, choose the difference in Date in the list. The window expands to show additional fields, as shown in the table below.
    5. Click OK to save your changes and close the window.

    In this area:

    Follow these steps:

    Last Date

    Click on the arrow down. uDesigner displays the list of all numeric fields on the form. In this list, choose the field that contains the later of the two dates that will be used in the calculation.

    Earliest date

    Click on the arrow down. In this list, choose the field that contains the first of the two dates that will be used in the calculation.

    Calculations based on

    Choose the calendar days to include all days of the week in the calculation. Choose the days of work to use only the working days of the week in the calculation.

  • Textarea conditional display based on the value of the checkbox.

    Hi all

    I have a question regarding the conditional display of an article based on the value of the checkbox.

    I have a checkbox in a region, which is a STATIC LOV:; Y and the text box in the same region. Now I want to show this textarea only if the check box is selected. ??

    Please suggest how to achieve this.

    Thank you

    DC

    Hello

    I guess that you are 4.2 Apex as you haven't shared the same.

    • Create a dynamic Action on change of box which should present the value of the checkbox and update the TextArea element.
    • Then continue as conditional Textarea with checkbox value.

    BR,

    Patrick

  • Conditional display based on the value of line

    I have a report table with several lines on it.  I need to post a link to another page of user action if a value in the line corresponds to an attribute of the user's role, so they can act on the item.  Other display or update the document would not be able to run the link.

    The logic of nickname would go something like this:

    If user_role = role_this_line_item then

    display approval_link

    on the other

    Hide approval_link

    end if

    I know how to write pl/sql to return to the display of the correct state of true/false, but I can't find out how to reference the value on the display line.  I tried: role_this_line_item, role_this_line_item, #role_this_line_item # and none of them return one value other than false.  How to refer to an attribute on the current line of the decision to hide/show correct?

    Al

    Al Wondra says:

    I use V4.2.6 Apex in local installation of Oracle 11 g XE.  I tried with IE, Firefox and Chrome.  None has the conditional display.

    The report is a standard report created using the Apex report wizard.  I'm one of the columns (the ID of the line) changing to conditionally a link to a page to data entry.  I only need one line at a time to be the active link.  No line should have a link, if the user is not the role is required to perform this action.

    You have described my question exactly, it seems, that the conditional rendering is applied to the entire column.  I need that it is applied to specific lines.  Some lines (1) will be the active link.  All other lines does not display the link.  Is this possible?

    If you want the value of the ID to display for each row returned by the report, but only rendered as a link, if the condition is true? The values used in the State come "role_this_line_item" seems to be a value of a column in the report. "User_role" is also a column value?

    The simplest option is to modify the column attribute display as for the Standard report columnID column and conditionally generate the link in the report query:

    select
        ...
      , case
          when user_role = role_this_line_item
          then
            'where DATA_ENTRY is the 'data entry page' target number or alias of the page.

  • Basic conditional script based on the number of lines in a text layer?

    Just received help here to write a conditional script by using the font size of a text layer. Thank you all for this.

    The next hurdle is a conditional script using the number of lines in a text layer in the differential. Far as I can tell it not the layer details which specify the number of lines. Just '\r' for a return in the idTxt descriptor. Nothing seems to stand for a soft return as far as I can tell. I'll probably have to be able to count the lines with soft and hard returns.

    Any thoughts?

    I was playing around with this a bit and here is a small script to determine the number of rows. This is based on the self in the head, that I calculated to environ.108 times the size of the font.

    #target photoshop
    app.preferences.rulerUnits = Units.POINTS;
    var doc = activeDocument
    var tL = doc.activeLayer
    var h = tL.bounds[3]-tL.bounds[1]
    var per = ((h/5)-(tL.textItem.size))/tL.textItem.size
    var num = h/(tL.textItem.size *1.108)
    
    alert(Math.round( num))
    
  • Avoiding the TRUNC as a condition of setting for the date of transaction

    I've never noticed this before, but tonight I have tested a query and made a trunc (mmt.transaction_date) between April 1, 2012"and 20 April 2012 ' in TOAD and I noticed it was taking a long time to run.

    If I remove the trunk and use mmt.transaction_date > = 1 April 2012 ' and mmt.transaction_date < 21 April 2012 "the query ran a lot faster and the explain command plan was also much better."

    Then I read that this truncing the date of the operation will be used the index on this field in the table when searching it.

    But if I change the setting so that the condition is set to add - it to the parameter, it does not work and maybe someone can help you. This is probably an obvious solution that I just think not.

    I created the discoverer as conditions:
    The operation date > =: Start Date of Transaction
    and
    The operation date < = (: Start Date of Transaction + 1).

    But I get an error "one of the arguments of the function has an invalid data type.

    Or maybe I'm wasting my time trying to avoid using the TRUNK on the date of the transaction?

    Kind regards
    Jerry

    Hello

    You should be OK with the condition:

    The transaction date > =: Start Date of Transaction and the Transaction Date< to_date(:transaction="" start="" date)="" +="">

    Rod West

  • Capture the content of the pdf presentation and create a new document based on the data?

    Are there programs that can capture the content of the pdf presentation and create a new document based on that? I want to convert the data from a pdf form to fill in an auto-generated shipping label. Thank you!

    Only field names that match exactly. You can use JavaScript and hidden fields to match the names of domain if necessary.

  • APEX4: How to create a report whose data are based on the date of entry of the user fields

    With the help of 4 Apex I create a report that allows the user to enter two dates and displays a report between the date range.

    How can I do this?

    Thank you.

    Go to Actions > filter in your IR and ther, you can create several conditions to filter your report.

    Denes Kubicek
    -------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    http://www.Amazon.de/Oracle-Apex-XE-Praxis/DP/3826655494
    -------------------------------------------------------------------

Maybe you are looking for

  • Open a tab, when you press a button

    Hi all I have trouble getting my VI to open a specific tab page when I press a button. I found the following trick in the forum: Use the nodes property.  First, get the page references.  In this table, select the specific page reference.  Then write

  • Wireless networks Windows Zero configuration is not available

    I have a Thinkpad under XP Pro SP3. Recently, I installed a wireless router and tried to connect the Thinkpad wireless, but the success of withoutr. I activated the Automatic Configuration Service and the ball of the taskbar says there are available

  • VGN-FS315N mass storage controller

    I just upgraded from XP to Windows 7 Edition Home Premium and I lost my sound, the volume level on the indicator of the speaker moves with music, I checked the Device Manager and found an exclamation point next to the mass storage controller. That wo

  • Cannot connect ipod

    Original title: installing drivers Ipod Hello Pascal. This is my story. I bought a new Apple Ipod Classic [160 GB] & im having problems with my desktop it doesn't install the drivers correctly. Measures: WIndows update is enabled [automatically recom

  • How can I fix C:\windows\debug

    OK so some time I installed a program and it worked fine. Now, when I try to run the program, I get an error that says "the file or the C:\windows\debug directory is corrupted and unreadable. Please run the utility Chkdsk."so after that I get that I