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)

Similar Messages

  • 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'

  • How to count the days between Date Range using OO ABAP?

    hi experts,
            i want to count the days between Date Range using OO ABAP for that  which class and method  can i use?.
    Thanks,
    Mahesh.

    Not sure I understand the requirement for it to be OO, but you could always write your own (i.e. use this):
    REPORT zz_date_diff.
    CLASS date_diff DEFINITION.
      PUBLIC SECTION.
        METHODS diff IMPORTING     i_date_fm TYPE d
                                   i_date_to TYPE d
                     EXPORTING     e_days    TYPE i.
    ENDCLASS."
    CLASS date_diff IMPLEMENTATION.
      METHOD diff.
        e_days = i_date_to - i_date_fm.
      ENDMETHOD."
    ENDCLASS."
    DATA: g_ref TYPE REF TO date_diff,
          g_days  TYPE i,
          g_date_fm  TYPE d VALUE '20080101',
          g_date_to  TYPE d VALUE '20090101'.
    START-OF-SELECTION.
      CREATE OBJECT g_ref.
      CALL METHOD g_ref->diff
        EXPORTING
          i_date_fm = g_date_fm
          i_date_to = g_date_to
        IMPORTING
          e_days    = g_days.
      WRITE g_days.

  • Date range using "Date Field" from basic component

    Hello Everyone,
    I have been trying to create date range option available on the dashboard based on 2 Date Filed component.
    Backend for this Dashboard is BW with using BEx query. I have a info object (Z_Date)
    Now I want to have 2 date box using Date Field component 1. Start Date 2. End Date.
    I have tried following
    1. Start Date - on Select
    DS_1.setFilter("Z_Date", {"low":StartDate.getDate()});
    2. End Date - on Select
    DS_1.setFilter("Z_Date", {"High":EndDate.getDate()});
    both the scripts do not have any problem but it doest work as it is suppose to be.
    I have also tried based on following How to write script for DATE Range
    But no luck so far.
    Please share if any one have achieved date range working as mentioned.
    Thanks,
    Rajan

    Hi,
    Set Default Date in Both Date Prompts initially .
    1. Start Date - on Select
    var startDate = StartDate.getDate();
    var endDate = EndDate.getDate();
    var varRange = startDate + " - " + endDate;
    DS_1.setFilterExt("Z_SDPCD", varRange);
    2. End Date - on Select 
    var startDate = StartDate.getDate();
    var endDate = EndDate.getDate();
    var varRange = startDate + " - " + endDate;
    DS_1.setFilterExt("Z_SDPCD", varRange);
    Or
    Select Dates First Then Provide a Button (Done) .
    And write code On Click Event of that Button
    var startDate = StartDate.getDate();
    var endDate = EndDate.getDate();
    var varRange = startDate + " - " + endDate;
    DS_1.setFilterExt("Z_SDPCD", varRange);

  • Date range using dual table

    I want to get the range of two date(two variables: e_date and s_date) in a proc code. Or I want to ensure the date range must be less than 180 days.
    I used: "SELECT to_date(:e_date1, 'DDMONYY') - to_date(:s_date1, 'DDMONYY') INTO :count FROM DUAL;" and "if (count <= 180)" in a proc code.
    I don't know whether there is some risks in that? Thanks.

    BluShadow wrote:
    EdStevens wrote:
    bill wrote:
    "There's a risk in using 2-digit years. Use 4-digit years to reduce errors."
    Because I only want to get the date range of two date(using :sdate and :edate variables), in anther words the relative value of two days, I think that 2 digits for the year part is permitted. Isn't it? Thanks.I can't believe Y2K was only 12 years ago and we are already forgetting the lessons.
    I few years ago (even closer to Y2k) I was in a conversation with a young programmer who expressed the opinion that Y2K was just a big hoax. After all, none of the bad things predicted really happened. I had to inform him that had he been around in 1998 and 1999 (I think he was in junior high at the time) he would have seen that the reason "nothing happened" is because armies of people like me spent two years working our a**** off to make sure nothing happened.Yep.... I was there too... checking...re-working...testing... just to ensure that everything went ok. I even had to go in and check all the servers on New Years day (oh, yes I made sure I got paid well for that one!) to make sure they were all still up and running. Only one server had a slight issue, but it was an oldie and not fixable and not a major issue.
    Yeah, me too. Sat in the server room all night watching the server light blink :-)
    Please, do yourself and your colleagues a favor and banish from your brain the entire concept of 2-digit years. When "modern" data processing got started, data records were limited to an 80-column punch card. We no longer have those constraints.4 digit years all the time.... oh yeah!You're just burying your head in the sand. It's time to start thinking about the Y10K problem, assuming we get through Dec. 21 :-)
    John

  • 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.

  • Discrete time range over date range  (using CR X1)

    Post Author: sjr
    CA Forum: Formula
    Can anyone show me how to select data over a discrete time range i.e. 6 p.m. till 11 p.m. per day, over a period of a month ?
    Using the data time parameter gives me data from 6p.m. on startdate right through till 11p.m. on endate.

    Here's a more detailed description...
    Create two formula fields to split the date and time from the data records (ds prefixed):
    dsDate
    dsTime
    Create two formula fields to split the date and time from the parameter fields (pm prefixed):
    pmStartDate
    pmStartTime
    pmStartDate
    pmStartTime
    Use your new formula fields in the record selector. Get to this off the Report menu button (in CR 2008):
    Report | Select Expert... | Record.
    You can pick the formula fields in the Forumula Editor to create something like:
    ({@dsDate} > {@pmStartDate} and
    {@dsDate} < {@pmEndDate}) and
    ({@dsTime} > {@pmStartTime} and
    {@dsTime} < {@pmEndTime)
    Tim

  • Date comparison using between function

    we are extracting the data between two dates and time with the below mentioned SQL. this same SQL extract different no of records with the same data on two different AIX server
    Both the database on the same version 9.2.0.8.0 and second is replica of first database.
    table column RCRE_TIME is date datatype
    SELECT AST.OPERATION,
    AST.CUST_ID,
    AST.RCRE_TIME,
    AST.KEY,
    HAC.ACCT_CLS_FLG,
    FROM HAC,AST
    WHERE HAC.FORACID = AST.KEY
    AND HAC.ENTITY_CRE_FLG = 'Y'
    AND to_date(AST.RCRE_TIME,'DD-MM-YYYY HH24:MI:SS') BETWEEN to_date('12-03-2012 20:22:28','DD-MM-YYYY HH24:MI:SS') AND to_date('13-03-2012 21:25:20','DD-MM-YYYY HH24:MI:SS')
    can any one help on the same.
    Thanks
    RSG

    user8448799 wrote:
    we are extracting the data between two dates and time with the below mentioned SQL. this same SQL extract different no of records with the same data on two different AIX server
    Both the database on the same version 9.2.0.8.0 and second is replica of first database.
    table column RCRE_TIME is date datatype
    SELECT AST.OPERATION,
    AST.CUST_ID,
    AST.RCRE_TIME,
    AST.KEY,
    HAC.ACCT_CLS_FLG,
    FROM HAC,AST
    WHERE HAC.FORACID = AST.KEY
    AND HAC.ENTITY_CRE_FLG = 'Y'
    AND to_date(AST.RCRE_TIME,'DD-MM-YYYY HH24:MI:SS') BETWEEN to_date('12-03-2012 20:22:28','DD-MM-YYYY HH24:MI:SS') AND to_date('13-03-2012 21:25:20','DD-MM-YYYY HH24:MI:SS')
    can any one help on the same.
    Thanks
    RSGsame results occur when everything is the same.
    different results occurs when something is different.
    How can we reproduce what you report?

  • Date range using Fiscal Year

    Hi,
    Please tell me the function module to get this data.
    My input is Fiscal Year -2008(for eg).
    I need the output with
              f_day = 01.04.2008
              l_day = 31.03.2009
    How to get this?

    Hi,
    I think SAP considers fiscal year from 01.01.2008 to 31.12.2008
    And FM for this is 'HR_E_GET_FISC_YEAR_DATES'
    So what u can do this is create an Z-FM and paste code as in Standard FM which is given above
    In code the changes will be
       FISC_FECINI = FISC_YEAR.
       FISC_FECINI+4(4) = '0401'.
       FISC_FECFIN = FISC_YEAR.
       FISC_FECFIN+4(4) = '0331'.
    Let me know further.
    Cheers,
    Parth Parikh

  • Date range: relation between two datepicker.

    Hi,
    I would change/update start date on the second datepicker when the user selected the date on the first datepicker.
    How can I manage it?
    Thanks.

    I did an error!
    It works!
    /* DatePicker */
            private void fromDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
                var fromPicker = sender as DatePicker;
                DateTime? data = fromPicker.SelectedDate;
                if (data != null)
                    toDatePicker.SelectedDate = data.Value.AddDays(1);
                    toDatePicker.DisplayDateStart = data.Value.AddDays(1);

  • Querying on date range issue?

    Hi,
    I'm looking for a solution for this issue,
    In the DB Table there is a column of type TIMESTAMP. so when i query for date range using BETWEEN keyword it returns data inserted on next day at 12.00.00 AM
    example :
    Table A
    ColumnA_
    data1
    data2
    data3
    ColumnTime_
    08/03/2010 11.55.00 AM
    08/04/2010 12.00.00 AM
    08/04/2010 12.00.01 AM
    here when I query using between (08/03/2010 and 08/04/2010) keyword on Column_Time then ,
    Ouput
    data1
    data2
    but I'm just looking for data1 in the output, any ideas?

    Between is inclusive of both boundaries:
    column between condition1 and condition2Translates into
    condition1 >= column
    and
    condition2 <= columnSo tell the code what you want ... in your case
    condition1 >= column
    and
    condition2 < columnI'm not sure if you expect the >= or not...adjust as needed.

  • How to export user using date range

    Hia , i am using Oracle10g my object to export user (pibs) all tables in pibs have
    created_date column
    i wan to export user pibs using date range created_date between 01-jan-07 and 05-jan-07
    pls help me

    Check out the QUERY clause.
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14215/exp_imp.htm#CEGFIAGE
    If you're using Datapump, check out Filtering during export operations.
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14215/dp_export.htm#g1022624

  • Ms Project 2013 report for resource name, tasks less than 100% complete within a date range I can set each time

    I have seen I can create a report for a resource name with a specified date range, and one that can show me for a resource name any incomplete tasks, but I want to do the following and cant work out how to state it in the report constructor:
    resource name equals - {I want to set a given resource in here}
    % complete is less than 100%
    start - date range is between [today -7 days] and [today +7 days]
    Please can someone show me how this is possible, I know it will be and it is me that has been defeated!!

    workspacedesign,
    Oops, my bad. I missed the point that the Name field for assignment rows will be the task name and that's not what you want. There is also a glitch in the date range filter. So, here's how to fix that.
    First, in the Resource Usage view, copy the Name field to Text1. Now select the resource line and do a fill down for all assignments under that resource. Do that for each resource. This could be automated with VBA, but for now, a manual setup should work
    fine.
    Second, instead of testing for the Name field in the filter, test for the Text1 field.
    Third, change the Finish test to be "less than or equal to".
    Now when you apply that filter, enter beginning date of your range and then the ending date of your range followed by the resource name. You should get the data you want.
    Unfortunately formulas in custom fields are not as flexible in Project as they are in Excel. For example, in Project a formula can only operate on data for that row. Further, even if you use the formula Today() +7 for your filter criteria, the first time
    the filter is used, Project will hard code today's date into the filter. The normal way around both of these shortcomings is to use VBA.
    Hope this helps.
    John

  • Date Range Within a Date Range

    I'm suffering from a mental block on this one and I'm hoping
    someone here can help. What I need to do is determine how many date
    ranges are between a broader date range. For example a school year
    runs from 9/1 to 6/30 or 180 work days. What I need to do is
    compute the number of 9/1 to 6/30 periods between say 1/1/2007 and
    9/30/2009. The result of this find is used in othere calculations
    in a rather complex report. Any help is appreciated.

    Yet another method...
    <cfset start_date = DateFormat('01/01/2007',
    'mm/dd/yyyy')>
    <cfset end_date = DateFormat('09/30/2009',
    'mm/dd/yyyy')>
    <cfset start_year = DatePart('yyyy', start_date)>
    <cfset end_year = DatePart('yyyy', end_date)>
    <cfset schoolyear_start = '09/01/'>
    <cfset schoolyear_end = '06/30/'>
    <cfset count = 0>
    <cfloop index="rec" from="#start_year#"
    to="#end_year#">
    <cfset tmp_start = DateFormat('#schoolyear_start##rec#',
    'mm/dd/yyyy')>
    <cfset tmp_end = DateFormat('#schoolyear_end##rec + 1#',
    'mm/dd/yyyy')>
    <cfif DateCompare(tmp_start,start_date) gt -1 and
    DateCompare(tmp_end, end_date) eq -1>
    <cfset count = count + 1>
    </cfif>
    </cfloop>
    <cfoutput>
    <br>There are #count# school year periods between
    #start_date# and #end_date#
    </cfoutput>

  • How can I get the start and end of a date range?

    Post Author: RobR
    CA Forum: Formula
    Greetings!
    I have a report whose records are selected if a date field is within the date range returned by the LastFullWeek function.  I want the header for that report to print the first and last dates in that range.  I don't see a way to extract those dates from a date range.  How do I do it?
    Also, I think it would be nice to be able to walk through a date range using a for loop, something along the lines of the following:
    for (thisDate in LastFullWeed)(    do something;)
    but I didn't see syntax like that in the help system.  If I could do this, then I could get the first and last date.  Is this possible?
    Thank you!
    RobR

    Post Author: SKodidine
    CA Forum: Formula
    If all you want is the starting date and ending date of the function LastFullWeek, then all you have to do is this:
    minimum(LastFullWeek) & '          ' & maximum(LastFullWeek);
    On a side note, from your post: for (thisDate in LastFullWeed)  Whatcha smokin'  Willis?? 

Maybe you are looking for

  • Auto Download "Stream" data

    Hey all, The issue I'm facing is part iTunes and part iCloud. I got my iPhone 4S a few days after it came out and restored it as an iCloud backup from my old 3GS. I was extatic that all my apps, contacts, calendars, etc. came down exactly how I had i

  • Conversion/noises in headphone

    Hi, I have two questions. 1.) How can I convert Logic Pro files into a format that can be read and edited by Cubase on a Windows computer and vice versa? Does Cubase need all of the files connected to the music data? 2.) Whenever I want to record my

  • Is my iPhone Faulty?

    My iPhone is a little over a week old. I've upgraded to 2.0.1. I've removed every 3rd party app. I've restored maybe 10 times - so I think that I have covered all the bases but: 1. Answering the phone is a unreliable operation. Sometimes my finger on

  • Exception in HttpConnectionParam

    Hi Friends, I am trying to send data using PostMethod class to server (I am not using JSP, I am using org.apache.commons.httpclient.methods.PostMethod ) program throws error at the following very first line and I checked it by putting system.out.prin

  • Mac won't boot up, help required!

    My mac came up with a message saying to power the mac down and re-boot it. I powered it down and now it won't boot back up again, just going to a blue screen with the curcular lines icon spinning round and nothing happens. It wont boot up in safe mod