Query with Date & TIME

Dear All,
I need to retreive data between date and time for which here is my where clause, which is not retreiving any data.
WHERE TRUNC(M.MR_DATE) BETWEEN :START_DATE AND :END_DATE
AND TO_CHAR(M.MR_DATE, 'HH24:MI') BETWEEN '23:00' AND '07:00'
Please help.
Thanks
Ahon
Please note: if I make the "time format" in reverse it is showing data:
WHERE TRUNC(M.MR_DATE) BETWEEN :START_DATE AND :END_DATE
AND TO_CHAR(M.MR_DATE, 'HH24:MI') BETWEEN '07:00' AND '23:00'

Thanks everyone,
to get the result I change the query something like below but it is showing same line item 2 times for each query which is correct, is there any way to bring them into one line.
SELECT D.DIV_ID, D.GRP_ID, D.ITM_ID, SUM(D.SENT_QTY)QTY, SUM(NVL(D.ITEM_TOT,0))GROSS, SUM(NVL(D.ITEM_COVRG,0))COVER,
SUM(NVL(D.TRAN_AMOUNT,0))CASH
FROM INV.SELL_OUT_DOCS M, INV.SELL_OUT_LINES D
WHERE TRUNC(M.MR_DATE) BETWEEN '20-FEB-2010' AND '20-FEB-2010'
AND TO_CHAR(M.MR_DATE, 'HH24:MI') BETWEEN '23:00' AND '24:00'
AND (M.MR_SERIAL=D.MR_SERIAL)
GROUP BY D.DIV_ID, D.GRP_ID, D.ITM_ID
UNION
SELECT D.DIV_ID, D.GRP_ID, D.ITM_ID, SUM(D.SENT_QTY)QTY, SUM(NVL(D.ITEM_TOT,0))GROSS, SUM(NVL(D.ITEM_COVRG,0))COVER,
SUM(NVL(D.TRAN_AMOUNT,0))CASH
FROM INV.SELL_OUT_DOCS M, INV.SELL_OUT_LINES D
WHERE TRUNC(M.MR_DATE) BETWEEN '20-FEB-2010' AND '20-FEB-2010'
AND TO_CHAR(M.MR_DATE, 'HH24:MI') BETWEEN '00:01' AND '07:00'
AND (M.MR_SERIAL=D.MR_SERIAL)
GROUP BY D.DIV_ID, D.GRP_ID, D.ITM_ID
ORDER BY GRP_ID,ITM_ID
result is something like this
P CNS 2709 (DIV_ID, GRP_ID, ITM_ID) 1 (QTY)
P CNS 2709 (DIV_ID, GRP_ID, ITM_ID) 3 (QTY)
Thanks for the help
Ahon

Similar Messages

  • How to query the Date/Time Dataype

    Hi,
    I am trying to query the database with Data/Time Datatype.
    String date=request.getParameter("date");
    String month=request.getParameter("month");
    String year=request.getParameter("year");
    String tosearch=month+"/"+date+"/"+year;
    String getTable="select * from tableRes where dmy='"+tosearch+"'";I would like to know why it is not working?
    I ran through tomcat and it appeared this error:
    Data type mismatch in criteria expression.
    Thanks!

    pramudya81 wrote:
    Rock,
    May I know more detail on your specs?
    What is your DB? Or how is exactly you execute the sql.
    to_date is anyway an Oracle syntax.
    So I guess your DB might be an SQL Server.
    to_date for oracle is equivalent as Convert in SQL Server
    example Select Convert(datetime ,'2002/01/01')
    Hope it works nowBad idea. See reply 1.

  • How to compare result from sql query with data writen in html input tag?

    how to compare result
    from sql query with data
    writen in html input tag?
    I need to compare
    user and password in html form
    with all user and password in database
    how to do this?
    or put the resulr from sql query
    in array
    please help me?

    Hi dejani
    first get the user name and password enter by the user
    using
    String sUsername=request.getParameter("name of the textfield");
    String sPassword=request.getParameter("name of the textfield");
    after executeQuery() statement
    int exist=0;
    while(rs.next())
    String sUserId= rs.getString("username");
    String sPass_wd= rs.getString("password");
    if(sUserId.equals(sUsername) && sPass_wd.equals(sPassword))
    exist=1;
    if(exist==1)
    out.println("user exist");
    else
    out.println("not exist");

  • Output triggred in the invoice with Date/Time 1

    Output triggred in the invoice with Date/Time as 1 i e Send with periodically scheduled job.
    So could you  let me know when this gets triggeed if we maintain 1 in condition record?
    Thanks,
    Praveen

    Hi Praveen,
    When you maintain 1in the Date/Time column in the Condition Records for O/P of say the Invoice it means that you are telling the system to send the O/P with periodically scheduled job.
    To achieve this you must use the report program RSNAST00.The message is processed through report program RSNAST00. This report program can be scheduled periodically or started manually.
    For scheduling periodically you need to set up a batch process in SM35.
    Hope this helps,
    J Nagesh

  • How to copy Log text (with Date, Time stamp ) User IDfrom BP to Transaction

    Hi Experts,
                     Can someone guide us how  to copy Log text (with Date ,Time & User ID) fron Business partner  (Prospect) to transactions by text detrmination procedure.
    Regards,
    Basavaraj Patil

    save text
    Fill out following parameters of SAVE_TEXT function module:
    HEADER
    TDOBJECT C 10 BUT000
    TDNAME C 70 10 digit BP number
    TDID C 4 Z001
    TDSPRAS C 1 Language
    INSERT = ’X’
    LINES
    TDFORMAT TDLINE
    |
    |testtttttttttttttttttttttttt( Your text)
    I would suggest you to use some other BAPI that would attach your text to BP than SAVE_TEXT.
    If you still wanted to use SAVE_TEXT then first make sure how the TDNAME is generated. It depends on the text determination procedure. For examples, it can be guid of BP, GUID followed by date or time or else the BP number itself.
    Just go to BP transaction, double click on the text pad, it will open you the SAP Script editor. Click on menu GOTO and select Header which will give you info about your TDID, TDOBJECT, TDNAME....
    Hope this helps.

  • With 10.7.2 update iCal does not allow you to set "Reminders" by draging events from "All Day Events" into "Reminders" is there another way to do this instead of having to type out the entire reminder with date, time, and type?

    With 10.7.2 update iCal does not allow you to set "Reminders" by draging events from "All Day Events" into "Reminders" is there another way to do this instead of having to type out the entire reminder with date, time, and type?
    With Lion 10.7.1. you where able to drag events from "All Day Events" into the "Reminders" bar to create upcoming reminders.

    Exactly the same question I was about to post!
    Great being able to sync reminders (well overdue) however if I have to re-type a calener envent into reminders it's a waste of time!! 
    Come on Apple!!
    Just need an option for the calender event to add to reminder or the old drag to add to reminder functionality back, Please???

  • Sql command not working with date time??

    I am using my own sql query to fetch data in the sql command.
    Due to the problem I found - here is the basic example:
    The sql is:
    select to_number(to_date('10/11/2011 10:23:00','dd/mm/yyyy hh24:mi:ss') - to_date('10/11/2011 10:20:00','dd/mm/yyyy hh24:mi:ss'))  minu  from dual
    But I am not getting anything in Crystal Report tool!!
    In any sql tool I get results.
    When I am not using time part (hh24:mi:ss) :
    select to_number(to_date('10/11/2011','dd/mm/yyyy') - to_date('09/11/2011','dd/mm/yyyy'))  minu
    from dual
    I am getting data!!!!
    What is the problem??
    Initially I had it with parameters of type 'Date Time'
    Please, any one knows what the problem is?

    Hi,
    Sorry for the delay and thanks for answering.
    It was partial solution
    Moving to oracle driver, not (OLE DB), this specific one worked fine:
    select to_number(to_date('10/11/2011 10:23:00','dd/mm/yyyy hh24:mi:ss') - to_date('10/11/2011 10:20:00','dd/mm/yyyy hh24:mi:ss'))*100 minu from dual
    BUT
    When I tried to change one of the hardcoded values to be parameter of type 'Date Time' I couldn't pass the validation step - mostly the errors:
    "ORA 00900 Invalid sql statment"   and
    "ORA - 00907: Missing right parnthesis"
    No matter which format I used.
    Last version is:  
    select to_date('{?tsStartReport}','yyyy-mm-dd hh24:mi:ss') from dual
    Any idea why 'Date Time; is so problematic? How can I workaround it?

  • *Urgent* Query with dates

    Hi Gurus,
    I am having problem in developing such a query which has calculations with dates. The problem is:
    I have
    base date for example 26-feb-2006
    statring day: 4
    interval: 5
    input date: 15-mar-2006
    Now the problem is I want to get the results from the query which will start 26-feb-2006+4 which is 02-mar-2006 and calculate the interval which is 5 days from '02-mar-2006' and run it every 5 (interval) days
    02-mar-2006
    07-mar-2006
    12-mar-2006
    I hope I have cleared everything.
    Please let me know as soon as possible.
    Thanks in advance.
    Aqil

    Where is the base_date coming from?
    declare
    v_jobno number;
    dbms_job.submit(v_jobno, 'SCHEMA_NAME.sp_my_proc();',
    -- first time running I schedule for 11 pm staring in 4 days
                              trunc(sysdate+4)+23/24,
    -- here the interval
                              'trunc(sysdate+5)+23/24' );
    end;

  • Error when trying to restrict query by Date/Time

    I'm running the following Power Query
    let
    ParamTable = Excel.CurrentWorkbook(){[Name="tbl_Parameter"]}[Content],
    StartDateRow = Table.SelectRows(ParamTable, each ([Parameter]="Start Date")), //Find row with Start Date, returns a table
    StartDate = StartDateRow{0}[Value], //Only 1 row in Table so assume row 0 is the value I want
    EndDateRow = Table.SelectRows(ParamTable, each ([Parameter]="End Date")),
    EndDate = EndDateRow{0}[Value],
    Source = Excel.CurrentWorkbook(){[Name="SAMPLE_Excerpt"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each [SAMPLED_DATE] >= StartDate and [SAMPLED_DATE] <= EndDate),
    #"Removed Duplicates" = Table.Distinct(#"Filtered Rows", {"PRODUCT"}),
    Products = Table.SelectColumns(#"Removed Duplicates",{"PRODUCT"})
    in
    Products
    The query returns the correct list but always has an extra error row with the following error message
    Expression.Error: Cannot apply operator < to types DateTime and Number.
    Details:
        Operator=<
        Left=1/1/2015 12:00:00 AM
        Right=42013
    42013 corresponds to 1/9/2015 which is not a date entered anywhere in my query or spreadsheet.  I tried using the DATETIME#() function to convert a text string to a date but still get the same message.
    Can anyone provide an example of restricting a query by a date range pulled from a parameter table in Excel?

    Hi,
    I think this errors due to different date and date time format . So that, you can correct the formula line of StartDate and EndDate to below :
    StartDate = DateTime.From( StartDateRow{0}[Value] )EndDate = DateTime.From( EndDateRow{0} [Value] )
    I hope this to help you.
    Regards,

  • Optimizing order by query with multiple time dimensions

    Hello all,
    I have two time dimensions, one a standard date dimension (Year,Qtr, Month, Week, Day) the other a user defined Time dimension (All, Hour, Minute, Second).
    I am joining my cube with my time dimension using only the 'All' level, so that I can get a single record for the Day level in my Date dimension. Under these circumanstances there aren't many records in my sample data. Less than 100 dates, although at the lowest level(seconds) there are approx 2 million records.
    In order to get my results back in order I am ordering by the date dimension day_end_date. The query is taking longer than I would expect given that there aren't many records at the Day Level. How can I ensure that my query is ordering based only on the values in the current day_level and not all day_end_dates values in the underlying cube.

    Changed order, speed improved significantly.

  • Doubt querying with dates

    Hi all,i have a doubt querying an sql statement which involves date.
      1  SELECT rsh.shipment_num "File#"
      2        ,mmt.transaction_date "Transaction Date"
      3  FROM rcv_shipment_headers rsh,
      4       ap_suppliers aps,
      5    po_headers_all pha,
      6    po_lines_all pla,
      7    mtl_system_items_kfv msi,
      8    rcv_shipment_lines rsl,
      9    rcv_transactions rcv,
    10    mtl_material_transactions mmt,
    11    mtl_transaction_types mtt
    12  WHERE rsh.vendor_id = aps.vendor_id
    13  AND pha.po_header_id = pla.po_header_id
    14  AND pla.item_id = msi.inventory_item_id
    15  AND pha.po_header_id = rsl.po_header_id
    16  and pla.po_line_id = rsl.po_line_id
    17  AND rsl.shipment_header_id = rsh.shipment_header_id
    18  AND rsl.item_id = msi.inventory_item_id
    19  AND rsl.to_organization_id = msi.organization_id
    20  AND rcv.shipment_header_id = rsh.shipment_header_id
    21  AND rcv.organization_id = msi.organization_id
    22  AND rcv.po_header_id = pha.po_header_id
    23  AND rcv.po_line_id = pla.po_line_id
    24  --and pla.org_id = msi.organization_id
    25  AND rsh.SHIPMENT_NUM = 'AP1005'
    26  --AND mmt.transaction_date = TO_CHAR(TO_DATE('14-SEP-2012','DD-MON-YYYY'))
    27  AND rcv.transaction_type = 'DELIVER'
    28  AND rcv.source_document_code = 'PO'
    29  --AND rcv.subinventory = 'Vessel'
    30  AND mmt.rcv_transaction_id = rcv.transaction_id
    31  AND mmt.transaction_type_id = mtt.transaction_type_id
    32* AND rcv.organization_id = 81
    SQL> /
    File#                          Transacti
    AP1005                         14-SEP-12
    AP1005                         14-SEP-12Now passing date
      1  SELECT rsh.shipment_num "File#"
      2        ,mmt.transaction_date "Transaction Date"
      3  FROM rcv_shipment_headers rsh,
      4       ap_suppliers aps,
      5    po_headers_all pha,
      6    po_lines_all pla,
      7    mtl_system_items_kfv msi,
      8    rcv_shipment_lines rsl,
      9    rcv_transactions rcv,
    10    mtl_material_transactions mmt,
    11    mtl_transaction_types mtt
    12  WHERE rsh.vendor_id = aps.vendor_id
    13  AND pha.po_header_id = pla.po_header_id
    14  AND pla.item_id = msi.inventory_item_id
    15  AND pha.po_header_id = rsl.po_header_id
    16  and pla.po_line_id = rsl.po_line_id
    17  AND rsl.shipment_header_id = rsh.shipment_header_id
    18  AND rsl.item_id = msi.inventory_item_id
    19  AND rsl.to_organization_id = msi.organization_id
    20  AND rcv.shipment_header_id = rsh.shipment_header_id
    21  AND rcv.organization_id = msi.organization_id
    22  AND rcv.po_header_id = pha.po_header_id
    23  AND rcv.po_line_id = pla.po_line_id
    24  --and pla.org_id = msi.organization_id
    25  --AND rsh.SHIPMENT_NUM = 'AP1005'
    26  AND mmt.transaction_date = TO_CHAR(TO_DATE('14-SEP-2012','DD-MON-YYYY'))
    27  AND rcv.transaction_type = 'DELIVER'
    28  AND rcv.source_document_code = 'PO'
    29  --AND rcv.subinventory = 'Vessel'
    30  AND mmt.rcv_transaction_id = rcv.transaction_id
    31  AND mmt.transaction_type_id = mtt.transaction_type_id
    32* AND rcv.organization_id = 81
    SQL> /
    no rows selectedCan anyone pls suggest me where i am doing wrong.
    Any help is appreciated,
    Thanks in advance

    You have already got your answer.
    >
    yes works out,thanks very much.May i know the reason why it didn't worked out earlier?
    Thanks
    >
    Hope, the below example will make things more clear to you.
    SQL> CREATE TABLE m003 AS
      2    (SELECT 1                                                       id,
      3            To_date('14/09/2012 23:00:00', 'dd/mm/yyyy hh24:mi:ss') dt
      4     FROM   dual
      5     UNION ALL
      6     SELECT 2,
      7            To_date('14/09/2012 00:00:00', 'dd/mm/yyyy hh24:mi:ss')
      8     FROM   dual
      9     UNION ALL
    10     SELECT 3,
    11            To_date('14/09/2012 01:00:00', 'dd/mm/yyyy hh24:mi:ss')
    12     FROM   dual
    13     UNION ALL
    14     SELECT 4,
    15            To_date('02/03/2012 23:00:00', 'dd/mm/yyyy hh24:mi:ss')
    16     FROM   dual);
    Table created.
    SQL> select * from m003;
            ID DT
             1 14-SEP-12
             2 14-SEP-12
             3 14-SEP-12
             4 02-MAR-12
    SQL> SELECT *
      2  FROM   m003
      3  WHERE  dt = To_char(To_date('14-SEP-2012', 'DD-MON-YYYY'));
            ID DT                                                                  
             2 14-SEP-12   Here, 14-SEP-2012 is a string. You are converting a string to date to compare with a column data which is a date. It does not make sense to convert to string again!
    SQL> select to_char(TO_DATE('14-SEP-2012','DD-MON-YYYY'),'DD-MON-YYYY HH24:MI:SS
    ')  from dual;
    TO_CHAR(TO_DATE('14-
    14-SEP-2012 00:00:00As you can see, TO_DATE('14-SEP-2012','DD-MON-YYYY') returns 14-SEP-2012 00:00:00.
    SQL> select * from m003
      2  where dt= TO_DATE('14-SEP-2012','DD-MON-YYYY');
            ID DT                                                                  
             2 14-SEP-12   In the above sql, it searches for the data that matches with date 14-SEP-2012 00:00:00 and hence 1 row.
    if your objective is to get the records where date is 14-SEP-2012 irrespective of the time associated with it,then write..
    SQL> select * from m003
      2  where dt >= TO_DATE('14-SEP-2012','DD-MON-YYYY')
      3  and dt < TO_DATE('14-SEP-2012','DD-MON-YYYY')+1
      4  ;
            ID DT                                                                  
             1 14-SEP-12                                                           
             2 14-SEP-12                                                           
             3 14-SEP-12     Now, what is the problem in below sql
    SQL> select * from m003
      2  where trunc(dt)= TO_DATE('14-SEP-2012','DD-MON-YYYY');
            ID DT                                                                  
             1 14-SEP-12                                                           
             2 14-SEP-12                                                           
             3 14-SEP-12   The SQL above will return same result as above BUT..
    In this case you are truncating the time for all the rows (ie time associated with the date will be 00:00:00) applying function trunc() which would be a bit slower. Moreover,
    if there is any index on this column then use of function on the column will ignore the index (if it is not a function based index).
    Hope it helps.
    Regards
    Biju

  • Query with date in where clause

    hi,
    i have build a view with join conditions from 8 tables. the data from this view is more then 100,000
    when i run the query with different clause its work with some seconds. but when i put date column in where cluase it sleeps.
    eg..
    where unit_id = 4 and t_id = 's09' and vb like '%amb%'
    works fine.
    where unit_id = 4 and t_id = 's09' and vb like '%amb%' and date between dt1 and dt2
    now sleep
    please ......give me some suggestions

    hi i have done the explain plan
    the result is
    Operation Object
    SELECT STATEMENT ()
    NESTED LOOPS ()
    NESTED LOOPS ()
    HASH JOIN ()
    HASH JOIN ()
    TABLE ACCESS (FULL) PR_PO_MST
    TABLE ACCESS (FULL) PR_SUPPLIER
    TABLE ACCESS (FULL) PR_PO_DTL
    TABLE ACCESS (BY INDEX ROWID) INDENT_MST
    INDEX (RANGE SCAN) ST_IND_MST_IDX
    TABLE ACCESS (BY INDEX ROWID) ST_ITEM
    Operation Object
    INDEX (UNIQUE SCAN) PK_ST_ITEM
    now wot do do????

  • How to compare Date in the TextField or DateTime with Date/Time field?

    Hi All,
    I am facing an issue with respect Date comparinson. I tried to look into entire discussions but failed to get the answer.
    My issue is: I wanted to comparet Date/time field value with Date value which is in TextField.
    The functionality of my form is:
    I have dropdown list which lists the registered customer ids binded to XML Datasource. On selection of the customer id from the dropdown I am displaying customer registration date in the TextField or say Date/Time field as below code in dropdown change event.
    RegistrationDetails.PurchaseEntry.txtRegDate.rawValue = regDataNode.CREATION_DATE.value; (this is TextField control)
    In form I have an Date/Time field in which use will select the date of item purchase. In the validation part I want to make sure that, the purchase date selected in Date/Time field must be greater than the Customer Registraiton Date. I able to compare if the customer selects the date from two different Date/Time fields. But how to compare the dates which one is in Date/Time field and Date is in TextField?
    I have tried using Num2Date and Date2Num with "YYYY-MM-DD"  format to compare but not succeed!
    Can you guys help me in this? Thanks in advance
    Regards.

    Hi,
    Yes, I am able to display the date which I have assigned to the text box. In the message box it show the value as '31/05/2009', since in this format i am assigining the date in the text box.
    Here is the code which I am assigning the value:
    RegistrationDetails.PurchaseEntry.txtRegDate.rawValue = regDataNode.CREATION_DATE.value;
    Do I need to change the format while assigning value in text box?
    You have told that, you have attached your test form, nothing is the reply. Can you repost the file?
    Regards.

  • Using the regex to match the file name with date time

    Hello all,
    currently I had problem to match the following file name with the date time. Of course I can use this regex like ""(\\\\w+|.+).(zip)" to match it. However in the current application i need to parse the file name and get the current date time to check if it is matched. Does anyone have good idea?
    {code}
    testfile10-08-09-2008-08-21-04-24-0443.zip
    testfile11-08-09-2008-08-22-04-24-0441.zip
    {code}
    thanks in advanced!

    lauehuang wrote:
    Hello all,
    currently I had problem to match the following file name with the date time. Of course I can use this regex like ""(\\\\w&#43;|.&#43;).(zip)" to match it.That regex doesn't make a lot of sense:
    - with "\\\\w" you probably meant "\\w";
    - "\\w&#43;|.&#43;" doesn't make sense: you can simply do ".&#43;" in that case;
    - ".(zip)" will also match the string "%zip" or "Ezip".
    However in the current application i need to parse the file name and get the current date time to check if it is matched. I don't know what you mean by that.

  • Creating a spool file with date/time appended to file name

    In Oracle Sql*Plus, I want to spool out a file, with the date-time stamp as part of the file name. Any idea how to do this?
    Here's what I have right now:
    SQL>
    set serveroutput on size 200000;
    rem
    rem $OFSA is a UNIX alias so sql plus is talking to UNIX
    rem
    spool $OFSA/logs/OFSAP/common_coa_id.log;
    prompt 'Enter date in mmddyyyy format, without quotes';
    exec upd_common_coa_id_driver ('&date_mmddyyyy');
    spool off;
    As an example, I'd like to have a file with this name: common_coa_id083002.log
    Thanks.

    In SQL*Plus this is what you can do to get the current date/time as part of the spool file:
    ============================================================================================
    SQL> column tm new_value file_time noprint
    SQL> select to_char(sysdate, 'YYYYMMDD') tm from dual ;
    1 row selected.
    SQL> prompt &file_time
    20020816
    SQL> spool C:\Temp\logfile_id&file_time..log
    . /* put your code here */
    . /* it will go to a file called C:\Temp\logfile_id20020816.log */
    SQL> spool off
    SQL>

Maybe you are looking for