BETWEEN function with dates

Hi,
how do i edit my where clause to display between the SYSDATE and exactly one month before that date?
i know it's something like
WHERE last_used >=SYSDATE
AND last_used is <=??????
i don't know what to put after that...
anybody know?

Daniel,
This might get you what you want:
WHERE last_used &gt;=SYSDATE
AND last_used is &lt;= add_months(sysdate, -1)
If this answers your question, please assign points and close the question..
Thank you,
Tony Miller
Webster, TX

Similar Messages

  • BETWEEN FUNCTION WITH IN A DECODE FUNTION IN A CURSOR

    The following below is my query..I have to get the hours,min and seconds from a 'yyyy-mm-dd-24hh.mi.ss' value and check if the time is between 12 am to 6 am , then write it with one value else write an another value..I am trying to use 'BETWEEN' function in decode function but i am getting error.....Can we use BETWEEN function with in decode function or is there any other way
    set serveroutput on
    declare
    cursor cur_dte is select lst_upd_date from EMPLOYESS ;
    begin
    for i in cur_dte loop
    DECODE (substr(trim(i.lst_upd_date),12)) ,between '00.00.00.0000' and '06.00.00.00.0000' ,101,102);
    dbms_output.put_line(i.lst_upd_date);
    end loop;
    end

    First of all. If you are in PL/SQL then CASE is just a more colmplex expression then IF THEN ELSE. I usually prefere If then else, but for some rare cases.
    The other issue is that you convert a datetime value into a string. This is wrong. it opens up all possible kinds of cenversion bugs. Stay with date or timestamp as long as possible.
    The solution depends a little upon the datatype of your lst_upd_date column.
    Here is a pl/sql solution assuming it is DATE.
    The TRUNC function can be used to reduce a datetime to a day or to an hour.
    declare
       cursor cur_dte is select lst_upd_date from employees ;
    begin
       for i in cur_dte loop
         if trunc(i.lst_upd_date,'HH') between trunc(i.lst_upd_date) and trunc(i.lst_upd_date)+6/24 then
            dbms_output.put_line(to_char(i.lst_upd_date,'DD-MON-YYYY HH24:MI:SS'));
         end if;       
       end loop;
    end;
    /But a pure SQL solution is much better.
    Here is how you implement it using CASE in SQL.
    example using pure sql
    select e.*,
            case when trunc(e.lst_upd_date,'HH')
                   between trunc(e.lst_upd_date) and trunc(e.lst_upd_date)+6/24
            then 101
            else 102
            end as "early_morning_check"
    from employees e;And if it is a timestamp column then you could use the EXTRACT function.
    select e.*,
            case when to_number(extract(hour from e.lst_upd_date))
                   between 0 and 6
            then 101
            else 102
            end as "early_morning_check"
    from employees e;You might want to consider if date values like 06:45:00 should be included or not.

  • How to use aggregate function with Date

    Hi All,
    I have a group of date from that is it possible to Max and Min of date.
    I have tried like this but its errored out <?MIN (current-group()/CREATION_DATE)?>.
    I have also tried like this but it doesnt works
    <?xdoxslt:minimum(CREATION_DATE)?>
    Is it possible to use aggregate function with date values.
    Thanks & Regards
    Srikkanth

    Hi KAVI PRIYA,
    if date is not in cannonical format, how can we change it in BI publisher, then how to calcualte minimum and as well as maximum.
    please advise me,
    Thanks,
    Sri

  • How to use TRUNC function with dates in Expression Builder in OBIEE.

    Hi There,
    How to use TRUNC function with dates in Expression Builder in OBIEE.
    TRUNC (SYSDATE, 'MM') returns '07/01/2010' where sysdate is '07/15/2010' in SQL. I need to use the same thing in expression builder in BMM layer logical column.
    Thanks in advance

    use this instead:
    TIMESTAMPADD(SQL_TSI_DAY, ( DAYOFMONTH(CURRENT_DATE) * -1) + 1, CURRENT_DATE)

  • Difference between initialization with data transfer?

    Dear Ones,
    What is the Difference between initialization with data transfer,initialization without data transfer and early delta initialization?
    Please explain me in senario basis..
    Thanks
    Shiva

    Hello Shivananda,
    See oss note 505700 :
    The early delta initialization is used to admit document postings
                in the OLTP system as early as possible during the initialization
                procedure.
    Regards,
    Fred

  • Between function for dates in Docmd.OpenReport rptName,,[date-filed] BETWEEN #date1# AND #date2# .. NOT WORKING

    Please assist, this is a nightmare indeed.
    Am trying to filter records in a report using the BETWEEN function, as below:
    strCondition = "Format([tblOrderLineTrack_main].[dtAllocation],'dd/MM/yyyy') BETWEEN Format(#06/02/2015#,'dd/MM/yyyy') AND Format(#07/03/2015#,'dd/MM/yyyy')" 
    DoCmd.OpenReport strDocName, acViewPreview, , strCondition, acWindowNormal
    The report is bringing up all records including those outside the specified range. What could be wrong with this???? Please assist, I am going nuts over this...

    The date literals I used are in the
    ISO standard for date notation of YYYY-MM-DD so are internationally unambiguous.  The only circumstance I can envisage in which it would not return the rows expected would be the extremely unlikely one where all the rows with dates in the range happen
    to have a date of 7 March 2015, and all have a non-zero time of day element.  There is no such thing in Access as a date value, only a date/time value so #2015-03-07# in fact represents the point of time at midnight at the start of 7 March 2015. 
    Any rows with date/time values of that date, but with a non-zero time of day would consequently fall outside the range.
    The above is so unlikely that I can't believe it to be the case, but the bullet-proof syntax would be:
        strCondition = "dtAllocation  >= #2015-02-06# " & _
              "AND dtAllocation < #2015-03-07#+1"
    i.e. all date/time values on or later than the start of the first day of the range (#2015-02-06 00:00:00#) and before the start of the day following the end of the range (#2015-03-08 00:00:00#)
    Assuming that the dtAllocation column is of date/time data type, and is returned as such in the report's RecordSource, not as a formatted string expression, I can see no reason on the information available why the above should not work, so if the report is
    still not returning any data some other reason not apparent to us must be suspected.  We are not in a position to debug the report, however, so what that might be I can't say.
    Ken Sheridan, Stafford, England

  • Trunc function with date

    when i use in my proceadure where trunc(timesent_acct) between '30-AUG-2006' and '27-SEP-2006' it returns 410 rows
    but
    when i use where timesent_acct between '30-AUG-2006' and '27-SEP-2006' it returns me 400 rows
    what actually happened out there my data stored in timestamp like this '9/27/2006 10:24:18 AM'
    what trunc actually do with dates
    thanks

    Hello,
    Trunc() without parameter retire the hour part of a date.
    SQL> alter session set nls_date_format='DD/MM/YYYY HH24:MI:SS'
      2  /
    Session modifiée.
    SQL> select sysdate, trunc(sysdate) from dual
      2  /
    SYSDATE             TRUNC(SYSDATE)
    07/11/2006 14:51:04 07/11/2006 00:00:00
    SQL> Francois

  • How to execute a function with date parameter as an input?

    HI
    I have a function named fun1(v_fun in date), with date as an input parameter and it returns a number. I have created the function successfully. But i couldnt execute this function in sqlplus. How to pass the dates? Can any one help me in this regard.

    Hi,
    V11081985 wrote:
    HI
    I have a function named fun1(v_fun in date), with date as an input parameter and it returns a number. I have created the function successfully. But i couldnt execute this function in sqlplus. It's hard for me to say what you're doing wrong when I don't know what you're doing. Post a complete test script that people can run to re-create the problem and test their ideas. Include a function definition, CREATE TABLE and INSERT statements for any of your own tables (if necessary), and the results you want to get from that data, as well as your query.
    How to pass the dates? Can any one help me in this regard.You can call the function like this:
    SELECT  fun1 (hiredate)  AS fun1_results
    FROM    scott.emp
    ;

  • Diff between init with data transfer and repair full request

    hi,
    i have observed that even in the new flow we are doing init without data transfer and then repair full request
    if i do init with data transfer also i can achieve the same?
    i want to know why we need to do this ,do we have any advantage of doing init without transfer and repair full request?
    please suggest me

    Hi Venkat,
    A repair full request is loaded in cases where you get erroneous records or where there are missing records which you want to load. In such cases, a repair full request for the selective records can be loaded and is the most efficient way to correct the data, since you won't be required to load the entire data once again. Also you acheive the desired result without disturbing the delta. (You are not required to do an init w/o data transfer after a repair full, people just do it a a precaution)
    However, repair full requests should only be loaded to infoproviders with update mode 'overwrite'. Otherwise, if the InfoProvider, its very probable that you might double the value of the key-figures due to rows being added twice - in case of an InfoProvider with update mode 'Additive'. So, if your InfoProvider is additive, you will need to delete the entire data and do an 'init with data transfer' to avoid corrupting the data. (Note: you can do a repair full request for an additive infoprovider in case of lost records or if you can delete erroneous records with selective deletion.But you have to be careful with the selections lest you inadvertently load other records than required and corrupt the data)

  • Query with scalar valued function with date filter

    Hello experts
    i have a problem by filtering my results with the date
    i have written the following code
    SELECT
    T1.ItemCode
    , T1.Dscription
    ,DBO.F_CALCULATION_QUANTITY(T1.ITEMCODE)
    FROM OINV T0 
    INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
    INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
    WHERE
    (T0.DOCDATE BETWEEN '2010-11-01' AND '2010-11-30')
    and (t2.cardcode ='80022')
    and (T0.CANCELED= 'N')
    group by  t1.itemcode, T1.Dscription, t2.suppcatnum
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    ALTER  FUNCTION [dbo].[F_CALCULATION_QUANTITY]
    (@ITEMCODE AS NVARCHAR(10))
    RETURNS
    NUMERIC(19,2)
    AS
    BEGIN
    DECLARE
    @RESULT1 AS NUMERIC(19,2),
    @RESULT2 AS NUMERIC(19,2),
    @RESULT AS NUMERIC(19,2)
    SELECT @RESULT1=SUM(A.QUANTITY)
    FROM INV1 A
    JOIN OINV B ON A.DOCENTRY=B.DOCENTRY
    WHERE A.ITEMCODE=@ITEMCODE
    AND B.DOCDATE BETWEEN  '2010-11-01 00:00:00.000' AND '2010-11-30 00:00:00.000'
    SELECT @RESULT2=SUM(A.QUANTITY)
    FROM RIN1 A
    JOIN ORIN B ON A.DOCENTRY=B.DOCENTRY
    WHERE A.ITEMCODE=@ITEMCODE
    AND B.DOCDATE BETWEEN '2010-11-01 00:00:00.000' AND '2010-11-30 00:00:00.000'
    SELECT @RESULT=ISNULL(@RESULT1,0)-ISNULL(@RESULT2,0)
    --SELECT @RESULT=@RESULT1- @RESULT2
    RETURN @RESULT
    END
    the problem i have is that i want to filter my results accoring to the date provided by the user. i want it to be dynamic query.
    by now, what i do is to edit the docdate in the function in order to get the desired results. this is not what i want.
    could you please help me on this way in order to let the user to input the date?if i add the [%] in the query, it does not bring me the right results

    i have already edited the function to
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    ALTER  FUNCTION [dbo].[F_CALCULATION_QUANTITY]
    (@ITEMCODE AS NVARCHAR(10),
    @STARTDATE1 as DATETIME,
    @ENDDATE1 AS DATETIME
    RETURNS
    NUMERIC(19,2)
    AS
    BEGIN
    DECLARE
    @RESULT1 AS NUMERIC(19,2),
    @RESULT2 AS NUMERIC(19,2),
    @RESULT AS NUMERIC(19,2)
    SELECT @RESULT1=SUM(A.QUANTITY)
    FROM INV1 A
    JOIN OINV B ON A.DOCENTRY=B.DOCENTRY
    WHERE A.ITEMCODE=@ITEMCODE
    AND B.DOCDATE BETWEEN (@STARTDATE1) AND (@ENDDATE1)
    SELECT @RESULT2=SUM(A.QUANTITY)
    FROM RIN1 A
    JOIN ORIN B ON A.DOCENTRY=B.DOCENTRY
    WHERE A.ITEMCODE=@ITEMCODE
    AND B.DOCDATE BETWEEN (@STARTDATE1) AND (@ENDDATE1)
    SELECT @RESULT=ISNULL(@RESULT1,0)-ISNULL(@RESULT2,0)
    RETURN @RESULT
    END
    could you please how to edit the query as well?
    i have added the following code and it comes up with the right itemcode but the quantity does not work
    DECLARE
    @ITEMCODE AS NVARCHAR(10),
    @STARTDATE1 as DATETIME,
    @ENDDATE1 AS DATETIME
    SET @STARTDATE1=(SELECT MAX(T0.DOCDATE) FROM oinv t0 WHERE T0.DOCDATE='2010-11-01')
    set @ENDDATE1=(SELECT MAX(T0.DOCDATE) FROM oinv t0 WHERE T0.DOCDATE='2010-11-30')
    SELECT
    T1.ItemCode
    , T1.Dscription
    ,DBO.F_CALCULATION_QUANTITY(@ITEMCODE,@STARTDATE1,@ENDDATE1)
    FROM OINV T0 
    INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
    INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
    WHERE
    (T0.DOCDATE BETWEEN @STARTDATE1 AND @ENDDATE1)
    and  (t2.cardcode ='80022')
    and (T0.CANCELED= 'N')
    group by  t1.itemcode, T1.Dscription, t2.suppcatnum
    the result is this
    70200     alert1     0.00
    70210     alert2     0.00
    70220     alert3     0.00
    70230     alert4     0.00
    as you can see the quantity is 0 and it shouldnt be
    Edited by: Fasolis Vasilios on Oct 31, 2011 10:49 AM

  • How to use MAX() function with date field

    Hi Frzz,
    I have created a Graphical calculation view in which i have multiple records for each employee with different dates. But my requirement is to take the records which have maximum date.
    I have converted the date into Integer and applied the MAX() function. But still am getting multiple records.
    Is there is any other way we can achieve this requirement in Graphical Calculation view??  Your suggestion will really help me.
    Thank  you.
    Krishna.

    Hmm... what have you tried out so far?
    Look, I took the effort and created a little example, just for you
    Assume we have a table that contains the logon dates of users.
    Every line contains the logon date and some info on the user.
    Very much like a not-normalized log file could look like.
    Now, the output we want is: one line per user with the most current logon time.
    Not too difficult:
    1. Have a aggregation node that gives you the distinct user details - one line for every user:
    2. Have another aggregation node that gives you the last (MAX) logon date per user:
    Finally you do a 1:1 join on the USER_ID and map the result to the output.
    Easy as pie
    - Lars

  • Query regarding Min function with Date

    Dear All,
    I have written query as follows but it is giving me error message.
    Selection CityCode, CityName, Min(Date)
    from Entry
    I want to write a query which should generate minimum date of transactions of city. There are about 50 cities in the Entry table and against each city there are thousands of records, I want to display only the oldest date against each city with its code. In the out put there should 50 rows as there are 50 cities and oldest (min) date. Can any one please help on this SQL.
    Thanks

    Do you want just min date in the table or need grouping by citycode and city name also?
    If just min date of the table is needed, use row_number analytic function to get the min date in the table.

  • Delta between ODS with Data field as key field

    Hello,
    I have a problem with a data load between two ODS. Below is the scenario
    ODS 1 has delivery data with delivery Doc and Delivery Item as key field and Plant,Material, Delivery Qty, etc..  as Data filed
    ODS 2 need to create as a aggregare at the plant, material level. So for ODS 2, Key Field is Plant, Material and the Data filed is Delivery Qty (additive), etc...
    When I load the Full load it works correctly, But when I bring the data as a delta it is updating the delivery Qty incorrectly and some of the data fileds are comming as blank also eventhough the source ODS (ODS1) has data.
    Can we use data filed from ODS1 as a Key filed for ODS2 ?
    Is that causing the
    Regards,
    Biju

    Hi,
    Looks like someone deleted/ added/ updated some entries in the change log table of ODS1.
    Did you check the "Change log" of ODS1 and compare with the delta request of ODS2?
    Isn't change log of ODS1 showing the entries you got as part of delta in ODS2?
    Another recommendation would be to compare the "Change log" of ODS1 with the "Active" table of ODS1 and see if they are showing the same value of the key figures.
    - Ashish

  • Where in clause vs. between clause with date conditions

    Hi Forum.
    I am struggling with two different query structures and wonder why one is more costly than the other one. Does anybody have any idea?
    Query a) Total Cost: 188. Bytes 511,966. Cardinality: 2,639
    Query b) Total Cost: 112. Bytes 511,966. Cardinality: 2,639
    Example:
    Query a) select * from table where trunc(date_time) between to_date('10/12/2011','DD/MM/YYYY') and to_date('20/12/2011','DD/MM/YYYY') and XYZ_ID = 007
    Query b) select * from table where trunc(date_time)
    in (
    to_date('10/12/2011','DD/MM/YYYY') ,
    to_date('11/12/2011','DD/MM/YYYY'),
    to_date('12/12/2011','DD/MM/YYYY'),
    to_date('13/12/2011','DD/MM/YYYY'),
    to_date('14/12/2011','DD/MM/YYYY'),
    to_date('15/12/2011','DD/MM/YYYY'),
    to_date('16/12/2011','DD/MM/YYYY'),
    to_date('17/12/2011','DD/MM/YYYY'),
    to_date('18/12/2011','DD/MM/YYYY') ,
    to_date('19/12/2011','DD/MM/YYYY') ,
    to_date('20/12/2011','DD/MM/YYYY')
    and XYZ_ID = 007
    -The table has local index on date_time and XYZ_ID
    -The table is partitioned like:
    PARTITION VALUES LESS THAN (TIMESTAMP' 2011-12-16 00:00:00')
    PARTITION VALUES LESS THAN (TIMESTAMP' 2011-12-17 00:00:00')
    etc.
    -Database: 11gR1
    If any other information needed, please ask for it.
    Thanks for this discussion!
    - Ugur-
    Edited by: user11384454 on 23.12.2011 04:56

    Hi,
    user11384454 wrote:
    I am struggling with two different query structures and wonder why one is more costly than the other one. Does anybody have any idea?
    Query a) select * from table where trunc(date_time) between to_date('10/12/2011','DD/MM/YYYY') and to_date('20/12/2011','DD/MM/YYYY') and XYZ_ID = 007
    Query b) select * from table where trunc(date_time)
    in (
    to_date('10/12/2011','DD/MM/YYYY') ,
    to_date('11/12/2011','DD/MM/YYYY'),
    to_date('12/12/2011','DD/MM/YYYY'),
    to_date('13/12/2011','DD/MM/YYYY'),
    to_date('14/12/2011','DD/MM/YYYY'),
    to_date('15/12/2011','DD/MM/YYYY'),
    to_date('16/12/2011','DD/MM/YYYY'),
    to_date('17/12/2011','DD/MM/YYYY'),
    to_date('18/12/2011','DD/MM/YYYY') ,
    to_date('19/12/2011','DD/MM/YYYY') ,
    to_date('20/12/2011','DD/MM/YYYY')
    and XYZ_ID = 007Because your 2 queries are functionnaly different.
    Query A would retrieve rows where date_time=to_date('10/12/2011 11:23:45','DD/MM/YYYY HH24:MI:SS') where the query B wouldn't.

  • Communication between servlets with data

    I have a servlet that creates a HTML table (a report) with some data. The data used is a vector of some java objects. Now, I want to add a hyperlink to each row in the table and when clicked, open a new browser window and show the record info in detail. I know how to add a hyperlink and open a new window, but I do not know how to pass the data associated with that (user-clicked) row to a new browser window. The Java object for that row contains 20 items and I do not want to pass them in name-value pair to another servlet. Is there a smarter way to do this ? Can someone please help me?
    This is a rough sketch of how I want to put a hyperlink in a row: The following method creates rows in my table:-
    private void loadTableData(Vector data, PrintWriter out, int col)
            throws IOException {
            MyRecordObject myRec = null;
            if (data != null) {
                Object[] myArray = null;
                myArray = new Object[data.size()];
                for (int k = 0; k < data.size(); k++) {
                    myArray[k] = data.get(k);
                Arrays.sort(myArray, new MySorterClass(col));
                for (int i = 0; i < myArray.length; i++) {
                    myRec = (MyRecordObject) myArray;
    out.println("<TR bgcolor= \"E5E5E5\"> ");
    // When the following hyper link
    //is clicked, pass "myRec" object to some servlet/JSP
    //and create a new HTML page with that data
    out.println("<TD> <a href=\"myDetailInfoServlet_with_data\" target =\"_blank\"> " + myRec.getName() + " </a> </TD>"); // <==
    out.println("<TD>" + myRec.getFathersName() + "</TD>");
    out.println("<TD>" + myRec.getMothersName() + "</TD>");
    out.println("<TD>" + myRec.getPetName() + "</TD>");
    out.println("<TD>" + myRec.getSpouseName() + "</TD>");
    out.println("</TR>");
    out.println("</TBODY>");
    out.println("</TABLE>");
    out.println("</div>");
    out.println("</html>");

    My approach would be to just pass along an id with the hyperlink. Something you use to identify which record you want to display. This can be the recordId, or maybe the index of it in the data vector if that is still available and hasn't changed.
    eg
    out.println("...<a href=\"myDetailInfoServlet_with_data\?id= " + i + " ...
    Also, I would recommend using JSPs for this sort of stuff.
    For sure, retrieve your data in a servlet, but then just put it into request/session variables, and forward to a JSP to display.
    using out.println for table code is a real pain in the butt.
    Cheers,
    evnafets

Maybe you are looking for

  • ITunes only plays one song at a time ... help please

    All of my songs are checked, but iTunes only plays one song at a time. I can't figure out why. Any suggestions? It just started doing this.

  • Adobe Document Services SP19

    Hi, We are running Adobe Document Services with MSS on NW04 EP6 SP15, with Adobe SP15. We are planning on upgrading the Portal components to SP19 and am wondering when SP19 of Adobe Document Services is going to be made available for download? Right

  • In need of desperate help 14yr old daughter's iPod is  a mess.

    When I plug it into the computer it is not showing up, although it makes the sound that it's connected. It just keeps saying "Do not disconnect" and is burning hot. I've tried to reset it and restore it. Now there are no songs on it. When I press sel

  • Midi Driver to Connect Keyboard To MacBook Pro

    I cannot find a Midi Driver that allows me to connect my Yamaha YPG-625 to Logic Studio on my MacBook PRO 8.2.  Any Suggestions?

  • Dual monitor with barebones

    I have a hermes barebone (845gl) with internal graphics. I want to use a pci slot to plug in a pci graphic card in order to get a desktop that extends across two monitors. Is there somebody that had done that?. What model of pci graphic card do yo us