Date range query between day1 and day1-14

I am using:
Oracle SQL Developer (3.0.04)
Build MAin-04.34
Oracle Database 11g
Enterprise Edition 11.2.0.1.0 - 64bit Production
I am having diffitult time getting this filter to work:
{Code}
where date_value between :day1 and :day1 - 14
{Code}
What am I doing wrong?
I am looking to input a single day and have it give a range of 14 days back. So if I put "25-JUN-2013" it should include that day and track back 14 days.

1007410 wrote:
where date_value between :day1 and :day1 - 14
Reverse the order.
You generally specify a range from LOW to HIGH. Or in dates, EARLIER to LATER.
You've done the reverse.
Basically instead of saying "Pick a number from 1 to 10", you said "Pick a number from 10 to 1".
with xx as
   ( select to_date('25-jun-2013', 'dd-mon-yyyy') d from dual union all
     select to_date('20-jun-2013', 'dd-mon-yyyy') d from dual union all
     select to_date('15-jun-2013', 'dd-mon-yyyy') d from dual union all
     select to_date('05-jun-2013', 'dd-mon-yyyy') d from dual
Select d
  from xx
where d between sysdate and sysdate-14 ;
no rows selected.
with xx as
   ( select to_date('25-jun-2013', 'dd-mon-yyyy') d from dual union all
     select to_date('20-jun-2013', 'dd-mon-yyyy') d from dual union all
     select to_date('15-jun-2013', 'dd-mon-yyyy') d from dual union all
     select to_date('05-jun-2013', 'dd-mon-yyyy') d from dual
Select d
  from xx
where d between sysdate-14 and sysdate;
D       
25-JUN-13
20-JUN-13
15-JUN-13
3 rows selected.

Similar Messages

  • Date range query  problem  in report

    Hi all,
    I have created a report based on query and i want to put date range selection but query giving problem.
    If i am creating select list selection then it is working fine means it will display all records on the particular date.
    But what i need is that user will enter date range as creation_date1,creation_date2 and query should return all the records between these date range. i want to pass it by creating items, i created two items and passing creation_date range to display all records but not displaying and if not passing date then should take null as default and display all records
    Here is the query:
    /* Formatted on 2006/12/10 20:01 (Formatter Plus v4.8.0) */
    SELECT tsh."SR_HEADER_ID", tsh."SALES_DEPT_NUMBER", tsh."COUNTRY",
    tsh."LOCAL_REPORT_NUMBER", tsh."ISSUE_DATE", tsh."SUBJECT",
    tsh."MACHINE_SERIAL_NUMBER", tsh."MACHINE_TYPE", tsh."MACHINE_HOURS",
    tsh."STATUS"
    FROM "TRX_SR_HEADERS" tsh, "TRX_SR_PARTS" tsp
    WHERE (tsh.status LIKE :p23_status_sp OR tsh.status IS NULL)
    AND (tsh.machine_type LIKE :p23_machine_type_sp)
    AND ( tsh.machine_serial_number LIKE
    TO_CHAR (:p23_machine_serial_number_sp)
    OR tsh.machine_serial_number IS NULL
    AND ( TO_CHAR (tsh.failure_date, 'DD-MON-YY') LIKE
    TO_CHAR (:p23_failure_date_sp)
    OR TO_CHAR (tsh.failure_date, 'DD-MON-YY') IS NULL
    AND ( TO_CHAR (tsh.creation_date, 'DD-MON-YY')
    BETWEEN TO_CHAR (:p23_creation_date_sp)
    AND TO_CHAR (:p23_creation_date_sp1)
    OR TO_CHAR (tsh.creation_date, 'DD-MON-YY') IS NULL
    AND (tsh.issue_date LIKE :p23_date_of_issue_sp OR tsh.issue_date IS NULL)
    AND (tsh.country LIKE :p23_country_sp OR tsh.country IS NULL)
    AND ( tsh.local_report_number LIKE TO_CHAR (:p23_local_rep_num_sp)
    OR tsh.local_report_number IS NULL
    AND ( tsp.part_number LIKE TO_CHAR (:p23_part_number_sp)
    OR tsp.part_number IS NULL
    AND tsh.machine_type IN (
    SELECT DISTINCT machine_type
    FROM trx_sales_dept_machine_list
    WHERE sales_department_id IN (
    SELECT DISTINCT sales_department_id
    FROM trx_user_sales_department
    WHERE UPPER (user_name) =
    UPPER ('&APP_USER.'))
    AND SYSDATE >= valid_from)
    AND tsh.sr_header_id = tsp.sr_header_id
    can any one tell me wat is wroung in this query.
    Any other way to write this?
    Thank You,
    Amit

    Hi User....
    Here is some date range SQL that my teams uses with some success:
    For date columns that do not contain NULL values, try this (note the TRUNC, it might help with your "today" problem).
    The hard coded dates allow users to leave the FROM and TO dates blank and still get sensible results (ie a blank TO date field asks for all dates in the future.
    AND TRUNC(DATE_IN_DATABASE)
    BETWEEN
    decode( :P1_DATE_FROM,
    TO_DATE('01-JAN-1900'),
    :P1_DATE_FROM)
    AND
    decode( :P1_DATE_TO,
    TO_DATE('31-DEC-3000'),:
    :P1_DATE_TO)
    For date columns that contain NULL values, try this (a little bit trickier):
    AND nvl(TRUNC(DATE_IN_DATABASE),
    decode( :P1_DATE_FROM,
    decode( :P1_DATE_TO,
    TO_DATE('30-DEC-3000'),
    NULL),
    NULL)
    BETWEEN
    decode( :P1_DATE_FROM,
    TO_DATE('01-JAN-1900'),
    :P1_DATE_FROM)
    AND
    decode( :P1_DATE_TO,
    TO_DATE('31-DEC-3000'),
    :P1_DATE_TO)
    Note the 30-DEC-3000 versus 31-DEC-3000. This trick returns the NULL dates when the FROM and TO date range items are both blank.
    I hope this helps.
    By the way, does anyone have a better way of doing this? The requirement is given a date column in a database and a FROM and a TO date item on a page,
    find all of the dates in the database between the FROM and TO dates. If the FROM date is blank, assume the user want all dates in the past (excluding NULL dates). If the TO date is blank, assume that the user wants all of the dates in the future (excluding NULL dates). If both FROM and TO dates are blank, return all of the dates in the databse (including NULL dates).
    Cheers,
    Patrick

  • Urgent - I have written select query between loop and endloop, Ple help out

    Can any one help out me on this select query. I have written select query between loop and endloop. When I execute the program it will take too much time in this query. Please help me out. Its very urgent.
    LOOP AT l_i_invoices ASSIGNING <l_invoices>.
          CLEAR alv_wa.
          alv_wa-bukrs = <l_invoices>-bukrs.
          alv_wa-gsber = <l_invoices>-gsber.
          CLEAR l_instid.
          CONCATENATE <l_invoices>-belnr <l_invoices>-gjahr INTO l_instid.
          SELECT top_wi_id FROM sww_wi2obj INTO TABLE l_i_swwwihead
                  WHERE catid   = c_catid_business_object
                    AND instid  = l_instid
                    AND typeid  = c_typeid_invoice
                    AND removed = space
                    AND ( wi_rh_task = c_task_buyer_message
                       OR wi_rh_task = c_task_buyer_message2 ).
          IF sy-subrc = 0.
            <l_invoices>-flag = 'X'.
          ELSE.
            <l_invoices>-flag = ' '.
          ENDIF.
          MODIFY l_i_invoices FROM <l_invoices> TRANSPORTING flag
                                WHERE belnr = <l_invoices>-belnr
                                   AND gjahr = <l_invoices>-gjahr.
          APPEND alv_wa TO i_alv.
        ENDLOOP.
    Thanks in advance.

    Here is a way to solve this problem.
    Choose somewhere before this loop processing to use that select. Therefore, you'll need use FOR ALL ENTRIES <that_loop_table> clause, and in the WHERE condition you need to specify that same fields.
    This way, you will have an internal table with all data you'll need to check.
    Then, inside your loop statement, use the READ TABLE command with the clause WITH KEY field = value, to read that record and use the value found.
    Like this sample:
      SELECT bukrs lifnr umsks umskz augdt augbl zuonr gjahr belnr buzei
             waers xblnr blart gsber ebeln zfbdt zbd1t zlsch
      INTO TABLE tg_bsak
      FROM bsak
      FOR ALL ENTRIES IN tl_bkpf_sel
      WHERE bukrs EQ tl_bkpf_sel-bukrs AND
            lifnr IN s_lifnr AND
            augbl EQ tl_bkpf_sel-belnr.
    LOOP AT tg_bseg INTO wa_bseg.
        READ TABLE tg_bsak INTO wa_bsak WITH KEY bukrs = wa_bseg-bukrs
                                                 gjahr = wa_bseg-gjahr
                                                 belnr = wa_bseg-belnr
                                                 BINARY SEARCH.
    if sy-subrc = 0.
    * do something
    endif.
    ENDLOOP.

  • Oracle 10g - Problem with Date Ranges using Between

    I am keeping track of patients who have not been contacted during a date range. if a nurse adds an event or note and the note is type 1,3,4 then this is a contact. The following works but if the event or note was made on the same day as the report is run, the current contact is not printed. Any help to improve the query and identify the problem would be appreciated. Also, if you add '1' to' n.created_date_time BETWEEN '10-Jan-2010' AND TRUNC(SYSDATE)' so it is ' n.created_date_time BETWEEN '10-Jan-2010' AND TRUNC(SYSDATE) + 1'. It works. What is wrong?
    SELECT upper(symptom_text),
      COUNT(UNIQUE(c.patient_id)) ,
      COUNT(UNIQUE(
      CASE
        WHEN e.eventdate BETWEEN '10-Jan-2010' AND TRUNC(SYSDATE)
        OR (n.created_date_time BETWEEN '10-Jan-2010' AND TRUNC(SYSDATE)
        AND n.note_type_id                                             IN (1,3,4))
        THEN c.patient_id
        ELSE 0
      END)) - 1
    FROM patient c,
      cust_info ci,
      event e,
      note n
    WHERE c.physician_id = 74
    AND c.patient_id      = ci.patient_id
    AND ci.info_type_id    = 32
    AND ci.symptom_text      IS NOT NULL
    AND c.patient_id      = e.patient_id(+)
    AND c.patient_id      = n.pk_id(+)
    AND n.table_name(+)    = 'patient'
    GROUP BY upper(symptom_text)
    ORDER BY DECODE(upper(symptom_text), 'A+', 1, 'A', 2, 'B', 3, 'C', 4, 'D', 5, 99)I suspect the end date is not inclusive. Fields are Date data types. Thanks for any help.

    Hi,
    achtung wrote:
    Understood. Frank was correct. Do you mean about the dates? Is that issue solved now?
    It would help a lot if you posted some sample data (CREATE TABLE and INSERT statements) and the results you want from that data. Simplify as much as possible. For example, if everything involving the e and n tables is working correctly, forget about them for now. Post a question that only invloves the c and ci tables.
    But, additionally, when a record in the cust_info doesn't exist my contact count is inaccurate. How can you explain this conceptually. I understand the query path is checking for this record due to the predicate. Perhaps the query should be redesigned. Thanks for your input!Again, you can see the results, and you know what they should be. Nobody else has that information. Please post some sample data and the results you want from that data.
    In your earlier message you said
    Could there be a problem if a record does not exist in the ci table?The condition:
    AND ci.symptom_text IS NOT NULL
    filters for this right? Maybe this could be part of the problem. why I'm not seeing records when a note is added to a patient's doc. How would this be technically be explained? You're doing a inner join between c and ci:
        AND c.patient_id      = ci.patient_id
        AND ci.info_type_id   = 32
        AND ci.symptom_text   IS NOT NULL ...Rows from c will be included only if there is a row in ci with the same patiend_id: even more, that matching row in ci must also have info_type_id=32 in a non-NULL symptom_text, otherwise, the row from c will be ignored.
    If you want rows from c to be included even if there is no matching row in ci, then do an outer join, like you're already doing with the e and n tables:
      WHERE c.physician_id = 74
        AND c.patient_id         = ci.patient_id (+)
        AND ci.info_type_id (+)  = 32
        AND ci.symptom_text (+)  IS NOT NULL
        AND c.patient_id         = e.patient_id(+)
        AND c.patient_id         = n.pk_id(+)
        AND n.table_name(+)      = 'patient'

  • Single day date range query

    I have a table with a created_date column. The datatype is DATE.
    When i query this table for some date range I do not ever get any results for a single day.
    e.g. select * from table where created_date >='29-Dec-2009' and created_date <='30-Dec-2009'.
    Result set = 5 records
    However,
    select * from table where created_date >='29-Dec-2009' and created_date <='29-Dec-2009'.
    OR
    select * from table where created_date >='30-Dec-2009' and created_date <='30-Dec-2009'.
    yield 0 records.
    Why is this so? I seem to be missing something obvious. Any pointers would be really helpful

    select * from table where created_date >='29-Dec-2009' and created_date <='30-Dec-2009'.means all created date between '29-Dec-2009 00:00:00' and '30-Dec-2009 00:00:00'
    select * from table where created_date >='29-Dec-2009' and created_date <='29-Dec-2009'.means all created date between '29-Dec-2009 00:00:00' and '29-Dec-2009 00:00:00'
    select * from table where created_date >='30-Dec-2009' and created_date <='30-Dec-2009'.means all created date between '30-Dec-2009 00:00:00' and '30-Dec-2009 00:00:00'
    So you need to correctly manage the time...
    select * from table where created_date >='29-Dec-2009' and created_date &lt; '30-Dec-2009'.To get only records at any time during Dec-29.
    select * from table where created_date >='30-Dec-2009' and created_date &lt; '31-Dec-2009'.To get only records at any time during Dec-30.
    select * from table where created_date >='29-Dec-2009' and created_date &lt; '31-Dec-2009'.To get only records at any time during Dec-29 and Dec-30.
    Max
    [My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/29/estrarre-i-dati-in-formato-xml-da-sql/]

  • Date range query

    I have the following query.
    I have a table that contains studentid,student_date_of_birthA second table contains studentid,class_passed,date_of_passingNow I want to know all students who passed their 'CLASS_X' during
    a particular date range and at the time of passing,the age of the student was 15 years.
    Any help would be greatly appreciated.
    Regards.

    Hi, this works in Oracle 9i
    SQL>SELECT studentid
    2 FROM table2
    3 JOIN table1
    4 USING (studentid)
    5 WHERE class_passed = 'CLASS_X'
    6 AND date_of_passing BETWEEN '&&Date1' AND '&&Date2'
    7 AND (FLOOR(MONTHS_BETWEEN('&Date1',student_date_of_birth)/12) = 15
    8 OR FLOOR(MONTHS_BETWEEN('&Date2',student_date_of_birth)/12) = 15)
    9 /
    Regards,
    Ely

  • Date range using BETWEEN

    I am trying to retrieve records that have a transaction date in a particular range to include the beginning and ending date. Simple enough, I thought. Here is the situation:
    SELECT * FROM TRANFILE WHERE
    TRANDATE BETWEEN &date1 AND &date2
    It picks up the records within the range but not those = to date2. Is that how BETWEEN should work (< date2) or should it pick up the records that are also equal to date2 (<= date2)?
    Thanks, sorry for such a simple question.

    BETWEEN is inclusive.
    If TRANDATE contains hours, minutes and seconds and date2 only the date the you'll only get the records from 0:00:00 on date2.
    Maybe what you meant was :
    SELECT * FROM TRANFILE WHERE
    trunc(TRANDATE) BETWEEN &date1 AND &date2
    or
    SELECT * FROM TRANFILE WHERE
    TRANDATE BETWEEN trunc(&date1) AND trunc(&date2)+1
    AND TRANDATE &lt;&gt; trunc(&date2)+1
    The latter will allow you to use an index on TRANDATE.
    The former could benefit from a function based index on trunc(TRANDATE)

  • Query between docdate and doctime

    Hi,
    I am having trouble in my query.I want to get the date that has date between 03/09/2015 and 03/10/2015 and time between 6:00AM of 03/09/2015 and 7:00AM of 03/10/2015 but it only show date with time between 6:00AM and 7:00Am of each date.
    This is my query
    SELECT T0.[DocDate], T0.[DocNum], T1.[Dscription], T1.[Quantity],T0.[DocTime] FROM OIGN T0  INNER JOIN IGN1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[DocDate] between [%0] and [%1] and T0.[DocTime] >= [%2] and T0.[DocTime]<=[%3]
    Thanks,
    Raphael

    Hi Raphael Mendoza
    Have you check the database does it have data between those time slot...
    Also you use between option
    SELECT T0.[DocDate],
       T0.[DocNum],
       T1.[Dscription],
       T1.[Quantity],
       T0.[DocTime]
    FROM OIGN T0
    INNER JOIN IGN1 T1 ON T0.DocEntry = T1.DocEntry
    WHERE T0.[DocDate] BETWEEN [%0] AND [%1]
      AND T0.[DocTime] BETWEEN [%2] AND [%3]
    Regards
    Kennedy

  • Joins query between itab and database table..

    Hi all,
    Is it posible to use joins query between internle table and data base table...

    Hi Mehboob,
    No thats impossible to join the internal table and the database table.
    Alternatively what you need to do is you need to execute a Queryin Database Table and use the For All Entries in itab.
    Eg:  Select * from marc into table it_marc
             for all entries in it_matnr
               where matnr = it_matnr-matnr.
    Thanks,
    Chidanand

  • Date Ranges Query

    Hi Experts,
    A very happy new year to all of you(to some in advance)!!
    I have a table where I have the employee id and task assigned with start dates & end dates. Overlapping dates of tasks is a data issue however I know how to spot them & eradicate them. So there will be no overlapping task dates
    Employee_id
    Task_No
    Task_Start_date
    Task_End_Date
    Sample Data
    1     T1     01-Jan-2014     28-Feb-2014
    1     T2     01-Mar-2014     31-Dec-2014
    2     T1     23-Jan-2014     31-Dec-2014
    2     T2     01-Jan-2015     31-Dec-2073 (Means end of time)
    3     T3     01-Jan-2014     15-Jul-2014
    3     T4     01-Aug-2014     31-Dec-2014
    4     T5     01-Jan-2014     31-Dec-2073
    I want to devise a query where i provide the end date & it will list out all the employees who are free for even one day starting 01-Jan-2014. So for example If I give 31-Dec-2014, it will list out
    EmpId     (First day on which the employee is free)
    2               01-Jan-2014
    3               16-Jul-2014
    If I give end date = end of time(31-Dec-2013), Expected Result -
    EmpId     (First day on which the employee is free)
    1               01-Jan-2015
    2               01-Jan-2014
    3               16-Jul-2014
    If I give end date = 31 Jan 2014, Expected Result -
    EmpId     (First day on which the employee is free)
    1               01-Jan-2015
    I devised following query, however it does not catch employee id 2. Also it does not provide flexibility to change end date-
    select *
      from (select employee_id,
                   task_start_date,
                   task_end_date,
                   lag(task_end_date, 1, task_start_date) over(partition by employee_id order by task_start_date) prev_end_date
              from shop.employee_tasks
             where task_end_date >= trunc(sysdate))
    where task_start_date - prev_end_date > 1
    Thanks in advance!!
    Regards,

    This is an example of what I call the "free time" query: you have the dates when you are busy and you want the dates when you are free.
    You can find a beautiful solution to the basic problem here: Ask Tom "SQL Query to find gaps in date ranges" (search for Antony Boucher's solution). Please note that this solution works even with overlapping date ranges.
    To apply the solution here, first create the test data (please do this yourself in later questions).
    create table t(Employee_id, task_no, Task_Start_date, task_end_date)
    as select
    1, 'T1', to_date('01-jan-2014'), to_date('28-feb-2014') from dual union all select
    1, 'T2', to_date('01-Mar-2014'), to_date('31-Dec-2014') from dual union all select
    2, 'T1', to_date('23-jan-2014'), to_date('31-dec-2014') from dual union all select
    2, 'T2', to_date('01-jan-2015'), to_date('31-dec-2073') from dual union all select
    3, 'T3', to_date('01-jan-2014'), to_date('15-jul-2014') from dual union all select
    3, 'T4', to_date('01-aug-2014'), to_date('31-dec-2014') from dual union all select
    4, 'T5', to_date('01-Jan-2014'), to_date('31-Dec-2073') from dual;
    In the query, you have to add records for yesterday and for the "end date" you want. This allows you to find "free time" before and after the date ranges in your table.
    Now you partition by Employee_id and order by Task_Start_date. Using the max(task_end_date) analytic function, you get the latest end date up to now. Add 1 to this and you get the first free date (maybe). To make sure that date is free, it has to be before the next start date.
    variable end_date varchar2(64)
    exec :end_date := '31-Dec-2073';
    with boundaries as (
      select trunc(sysdate)-1 task_start_date, trunc(sysdate)-1 task_end_date from dual
      union all
      select to_date(:end_date)+1, to_date(:end_date)+1 from dual
    ), data as (
      select * from t
    where task_end_date >= trunc(sysdate)
      and task_start_date < :end_date
      union all
      select distinct a.employee_id, null, b.task_start_date, b.task_end_date
      from t a, boundaries b
    select employee_id, min(free_start) free_start
    from (
      select employee_id,
      max(task_end_date) over (partition by employee_id order by task_start_date)+1 free_start,
      lead(task_start_date) over (partition by employee_id order by task_start_date)-1 free_end
      from data
    where free_start <= free_end
    group by employee_id;
    EMPLOYEE_ID
    FREE_START
    1
    01-JAN-15
    2
    01-JAN-14
    3
    16-JUL-14

  • Real-Time Data Sync-up between Oracle and MS SQL Server

    Hi All,
    I am looking for a solution to sync-up the data between Oracle and MS SQL Server in real time. Here, the structure of table is different (in the sense, the data in multiple table in SQL Server should be combined and put it in a single table in Oracle and vice versa).
    Could anybody throw light on this plz?
    Thanks in advance!

    mt**** wrote:
    Hi All,
    I am looking for a solution to sync-up the data between Oracle and MS SQL Server in real time. Here, the structure of table is different (in the sense, the data in multiple table in SQL Server should be combined and put it in a single table in Oracle and vice versa).
    Could anybody throw light on this plz?
    Thanks in advance!Handle:     mt****
    Status Level:     Newbie
    Registered:     Feb 9, 2003
    Total Posts:     183
    Total Questions:     14 (10 unresolved)
    why so MANY unanswered questions?
    what should occur when DML occurs & the "other" DB is not online?

  • Need suggestions on date range query

    I have a requirement to show the amount of product remaining. There is a table that holds updated "inventory" amounts with a date and tonnage, and a series of transactional tables that detail the individual disbursements from the stockpile. The trick is that the dates for the inventory adjustments may not all be the same, meaning that I need to individually resolve the stockpiles.
    This query will give me the inventory disbursements:
    select FN_STN_KEY(j.FACTORY_ID, j.STATION_ID) as STATION,
      count(j.LOAD_JOB_ID) as LOADS,
               CASE SUM(w.SPOT_WEIGHT)
                 WHEN 0 THEN SUM(NVL(j.MAN_SPOT_WT,0))
                 ELSE SUM(w.SPOT_WEIGHT)
               END TONS
           from TC c, TC_LOAD_JOBS j, SPOT_WEIGHTS w
          where c.TC_ID = j.TC_ID
            and c.DATE_INDEX = w.DATE_INDEX and j.LOAD_RATE_ID = w.LOAD_RATE_ID
            and c.DATE_INDEX BETWEEN to_date('09/01/2009','MM/DD/YYYY') and sysdate
            and FN_STN_KEY(j.FACTORY_ID, j.STATION_ID) in (810,410)
          group by FN_STN_KEY(j.FACTORY_ID, j.STATION_ID);Note that the date and the list of stations in the where clause are dynamic and selected by user. If this was only one station at a time it wouldn't be this complicated.
    This query will give me the last known inventory amount:
    select to_char(MAX(AS_OF_DT),'Mon DD, YYYY'), TONS
      from STATION_LOG
          where AS_OF_DT < sysdate and STN_KEY in (810,410) group by TONS;Again, the date and list of stations are selected by user. They should be identical to those selected for the other query.
    Does anyone have any good ideas on how to combine these two statements into a single report?
    Note: FN_STN_KEY acts as a join function. You don't really want me to get into why there isn't a single unique key to reference.

    Hi,
    I'm trying to follow your descrioption, but lots of things don't make sense to me.
    blarman74 wrote:
    Yeah. I put in some data so I could get the message back to you, then filled in the rest.
    So the user is going to pass in two parameters: The date of the report and the list of stations they want to get an inventory count on. What were the parameters that produced the output you posted before:
    STATION     INITIAL_TONS     USED_TONS     AS_OF_DATE
    810               835500        465100      09/01/2010
    410               495800        366900      09/02/2010
    550               568900        122600      08/31/2010
    What I need the report to do is
    1) take a station from the list
    2) find out the inventory tally from STATION_LOG where the date is the largest date less than the supplied date. This should give me AS_OF_DATE and my initial quantity.
    3) query the data table for all tons hauled from the AS_OF_DATE for that station.
    4) repeat for the next station.So this is what your existing PL/SQL code does. A non procedural language, like SQL, won't follow the same steps, of course.
    The sample data for station_log is:
    INSERT INTO STATION_LOG (1, to_date('08/31/2010','MM/DD/YYYY'), 810, 562500);
    INSERT INTO STATION_LOG (2, to_date('09/02/2010','MM/DD/YYYY'), 410, 495500);
    INSERT INTO STATION_LOG (3, to_date('09/01/2010','MM/DD/YYYY'), 910, 832600);
    INSERT INTO STATION_LOG (4, to_date('12/31/2010','MM/DD/YYYY'), 810, 239800);How do you get the initial_tons in the output above from the data above? Did you mean to post some new sample data for station_log?
    I still get ORA-00928 errors from all the INPUT statements.
    As I said, I can do it inside a loop in PL/SQL, but I got completely stumped on how I could accomplish this in SQL. The trick is that if I can do it in SQL, I can allow the user to export the data to csv using built-in functionality. If I have to do it in PL/SQL, I can't provide the export as easily.
    One more thing I just thought about, I am going to need to use a BETWEEN on the dates of the data I need to grab. I obviously don't want to grab data past another inventory tally record from STATION_LOG for the same station, and I can use an NVL so it cuts off at SYSDATE. I obviously haven't hauled anything in the future ;)I doubt if I'll get enough information to do this for you before I leave on vacation.
    Here's an example of what you need to do using the scott.emp table instead of your station_log table:
    SELECT       job
    ,       hiredate
    ,       sal
    FROM       scott.emp
    ORDER BY  job
    ,            hiredate
    JOB       HIREDATE           SAL
    ANALYST   03-Dec-1981       3000
    ANALYST   19-Apr-1987       3000
    CLERK     17-Dec-1980        800
    CLERK     03-Dec-1981        950
    CLERK     23-Jan-1982       1300
    CLERK     23-May-1987       1100
    MANAGER   02-Apr-1981       2975
    MANAGER   01-May-1981       2850
    MANAGER   09-Jun-1981       2450
    PRESIDENT 17-Nov-1981       5000
    SALESMAN  20-Feb-1981       1600
    SALESMAN  22-Feb-1981       1250
    SALESMAN  08-Sep-1981       1500
    SALESMAN  28-Sep-1981       1250Say we want to find, for each job in a given list, the sal that corresponds to the last hiredate that is no later than the given report_date. (This seems pretty close to what you heed: fior each stn_key in a given list, the quantity that corresponds to the last row that is no later than the given report_date.)
    That is, if we're only interested in the jobs CLERK, MANAGER and PRESIDENT, and only in hiredates on or before December 31, 1981, the output would be:
    JOB       LAST_HIREDA   LAST_SAL
    CLERK     03-Dec-1981        950
    MANAGER   09-Jun-1981       2450
    PRESIDENT 17-Nov-1981       5000That is, we want to ignore all jobs that are not in the given list, and all rows whose hiredate is after the given report_date. Among the rows that remain, we're interested only in the last one for each job.
    Note that the last_sal for CLERK is not 1300 or 1100: those values were after the given report_date. also, the last_sal for CLERK is not 800; that's not the last one of the remaining rows.
    Here's one way to get those results in pure SQL:
    DEFINE       jobs_wanted     = "CLERK,MANAGER,PRESIDENT"
    DEFINE       report_date     = "DATE '1981-12-31'"
    SELECT       job
    ,       MAX (hiredate)                         AS last_hiredate
    ,       MAX (sal) KEEP (DENSE_RANK LAST ORDER BY hiredate)     AS last_sal
    FROM       scott.emp
    WHERE       hiredate     <= &report_date
    AND        ',' || '&jobs_wanted' || ','     LIKE
           '%,' || job                  || ',%'
    GROUP BY  job
    ORDER BY  job
    ;I used substitution variables for the parameters. You could use bind_variables, or hard-code the values instead.
    The WHERE clause is applied before aggreate functions are computed, so rows after &report_date don't matter.
    "MAX (sal) KEEP (DENSE_RANK LAST ORDER BY hiredate)" means the sal that is associated with the last row, in order by hiredate. If there happens to be a tie (that is, two or more rows have exactly the same hiredate, and no row is later) then the highest sal from thsoe rows is returned; that's what MAX means here. Ties may be impossible in your data.
    You need to write a similar query using your station_log table, and join the results of that to your load_data table, including only the rows that have dates between the date in the sub-query (last_hiredate in my example) and the parameter report_date. That can be part of the join condition.

  • Date Range Calculations for gaps and overlaps

    Oracle version: 11.2.0.3
    Platform : Linux
    Empno       position    start_dt       end_dt
         1                X            01/01/2008  01/02/2010
         1                Y           01/02/2009  12/31/2012
         1                X           02/01/2012   04/01/2013    
         1                Z           5/01/2012    12/31/2012
         1                Y           05/01/2013  present         
    I need to find the exact time period the employee worked for the company in a particular position. The query should be able to calculate the overlap/gaps accordingly
    For example in this case the result should be
    Empno  position   days    Total_Days
    1             x              1156        2943
    1             y              1543        2943
    1             z               244        2943
    Thanks
    Kevin

    Hi, Kevin,
    Assuming you do have overlaps (and depending on what you mean by "overlaps") here's one way to handle them:
    WITH got_new_grp AS
       SELECT  empno, position, start_dt
       ,       NVL (end_dt, TRUNC (SYSDATE)) AS end_dt
       ,       CASE
                   WHEN  MAX (end_dt)
                             OVER ( PARTITION BY  empno, position
                                    ORDER BY      start_dt
                                    ROWS BETWEEN  UNBOUNDED PRECEDING
                                         AND      1         PRECEDING
                                  ) < start_dt
                   THEN  1
                   ELSE  0
               END  AS new_grp
        FROM   table_x
    --  WHERE  ... -- If you need any filtering, put it here
    , got_grp  AS
        SELECT  empno, position, start_dt, end_dt
        ,       SUM (new_grp) OVER ( PARTITION BY  empno, position
                                     ORDER BY      start_dt
                                   )  AS grp
        FROM    got_new_grp
    SELECT DISTINCT
              empno, position
    ,         SUM (MAX (end_dt) - MIN (start_dt))
                  OVER (PARTITION BY empno, position)   AS days
    ,         SUM (MAX (end_dt) - MIN (start_dt))
                  OVER (PARTITION BY empno)             AS total_days
    FROM      got_grp
    GROUP BY  empno, position, grp
    ORDER BY  position
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Point out where the statement above is getting the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Difference in data transfer rates between winXP and Linux server?

    Hello all,
    I am using a winXP laptop to act as my server (all usb external hard drives are connected to it) but the data transfer rates can be really slow. Is Linux faster in that regard? Can a Linux based server provide faster data transfer rates?
    Thanks for any help.
    Bmora96

    Linux cannot make hardware go any faster - so if WinXP and its drivers are making optimal use of those USB drives and the USB data transfer pipe, Linux will not make it faster. (but installing Linux and going Tux are always excellent ideas that need no real reason either ;-) )
    Real question you should be asking is if using a notebook in a server role is wise thing to do?

  • Data Transfer methods between FPGA and RT

    I have 10 values that I combined into a cluster that I want to send to the RT controller.  The problem is if I just the read/write FPGA, I only get 1/10th of the data.  I am assuming that it is the time taking to transfer from FPGA to RT.  So I looked into DMA FIFO.  When I use this, I do capture the data, but I notice jumps/shifts in the data.  It's almost like the buffer fills up, and then dumps it at the last sec. To reduce this, I went from 10 values from the cluster to 2, and there were not shifts/jumps.  The problem is I need all 10 values.  So I'm wondering if I need to increase my DMA FIFO or if there is another meathod I need to use like Shared Varibles? 
    Thanks,
    guilio

    The one thing I still don't understand is what you mean by this "jump" in your data. Can you be a bit more specific about this? What I mean by jump.  The elements coming from the FIFO in the RT controller will display on my array visual aid normally.  Then you will see the data jump. Here is an example.  I am bringing out 3 elements, X Y Z into an array.  I'll read lets say 9 elements at a time.  So my array, after I transform it into a 2D array for saving will look like this.  [x y z;x y z;x y z].  At some points in time, the array will jump and look like this. [x y z;z x y ;z x y].  Then it will go back to how I expect it to look [z x y;x y z;x y z].  Right now, I am reading ~3000 elements.  The elements remaining depends on what else is going on.  If the visual aids are deleted, then elements remaining will never max out and thus, I won't get jumps.  If I put visual aids in, then I get jumps because elements remaining maxes out.  This leads me to believe that the FIFO is filling up and since it can't release all the information fast enough, then it just dumps it and fill it up again.  The weird thing about it, It doesn't happen in a pattern (every 3000 elements).  I tried putting them in seperate loops, it still slows things down.  I tried queing/dequeing, still slows it down.  I need to be able to read all elements fo all 3 DMA transfers at once.   Maybe it will help us locate the problem.  Otherwise, your DMA FIFO looks OK.  Can you verify the number of times your data is written to the FIFO from the FPGA? When I put a clock in to measure loops speed, it was showing 8-9us.  I can't have this no more than 10us or I will missed data. I would like to see a definite count of this.  Then on the RT side, what does the "Elements Remaining" output look like?  As before, elements remaining depends on what else is going on.  If I just have the DMA FIFO's, then I can adjust the read elements number so all three don't max out, but as soon as I put something else in, it will max out.  Since this is a FIFO we should be able to keep very close track of elements in and out.
    Let me know if you need more info.  I know about the FXP point transfer, unfotunately, not all my FXP elements are the same data type.
    Thanks,
    guilio

Maybe you are looking for