Compare date in SQL statement

yup.. how can i compare date in SQL statement??
pls give me a completed example.

I'd think this is a formatting problem. Why not try:
PreparedStatement ps = myConnection.prepareStatement(
"SELECT * FROM Receipt WHERE to_date(Date) > ? ");
ps.setDate(1,TodayDate);
ResultSet rs = ps.executeQuery();
HTH,
Ken

Similar Messages

  • Compare blob in SQL statement

    Hi,
    Is it possible to compare blob in SQL statement?
    Example:
    Table1 (id number
    image long raw);
    Table2 (name varchar2
    pic long raw);
    select id, name from table1, table2
    where image = pic

    Hi,
    Try the following and see if it works :
    I have TEXT in the LONG RAW column and not image
    files.
    Method I
    You can use PL/SQL to check if the 2 Long RAW Columns are
    identical or not :
    NOTE :- PL/SQL however has a limitation of processing
    data size less than 32k in size. If the
    Long Raw column exceeds 32k in size then PL/SQL
    cannot be used.
    SQL> desc temp9;
    Name Null? Type
    ID NUMBER
    COL1 LONG RAW
    SQL> desc temp9a;
    Name Null? Type
    ID NUMBER
    COL1 LONG RAW
    SQL> @t
    Id = 1, Long Raw is not the same
    Id = 2, Long Raw is the same
    PL/SQL procedure successfully completed.
    SQL> select id from temp9;
    ID
    1
    2
    SQL> get t
    1 Set ServerOutput On Size 999999;
    2 Declare
    3 CURSOR c1 Is
    4 Select id, col1
    5 from temp9;
    6 xCol1 Temp9a.Col1%Type;
    7 BEGIN
    8 For x In c1 Loop
    9 Select col1
    10 Into xCol1
    11 From temp9a
    12 Where id = x.id;
    13 If ( x.col1 = xCol1) Then
    14 Dbms_Output.Put_Line ('Id = ' || x.id || ', Long Raw is the same');
    15 Else
    16 Dbms_Output.Put_Line ('Id = ' || x.id || ', Long Raw is not the same');
    17 End If;
    18 End Loop;
    19 END;
    20* /
    Method II
    You can create a Database function for the above script and use it within
    your SQL .
    -- Shailender Mehta --

  • How to parsing xml data in sql statement??

    Hi friends, I have a table which contain column as clob ,stores in xml format, for example my column contain xml data like this
    <Employees xmlns="http://TargetNamespace.com/read_emp">
       <C1>106</C1>
       <C2>Harish</C2>
       <C3>1998-05-12</C3>
       <C4>HR</C4>
       <C5>1600</C5>
       <C6>10</C6>
    </Employees>
      Then how to extract the data in above xml column data using SQL statement...

    Duplicate post
    How to parsing xml data in sql statement??

  • Oracle Date in SQL Statement.

    Hello,
        We are having performance issues with some reports using conditions on date fields in the Record Selection Formula. Our application does not use the time portion of the date fields very often. When Crystal Reports builds the SQL statement to Oracle it uses a range condition to include all the possible time values. This practice makes a big difference compared to a direct condition
         Example:   SELECT "TABLE_A"."ID"
                           FROM   "TABLE_A"
                           WHERE  ("TABLE_A"."DT">= TO_DATE('2011-03-31 00:00:00','YYYY-MM-DD HH24:MI:SS') AND
                                          "TABLE_A"."DT"< TO_DATE('2011-04-01 00:00:00','YYYY-MM-DD HH24:MI:SS'))
         Is there a way to tell Crystal not to perform range validation on dates?
         We would like to have a SQL Statment that looks like:
                           SELECT "TABLE_A"."ID"
                           FROM   "TABLE_A"
                           WHERE  ("TABLE_A"."DT" = TO_DATE('2011-03-31'))
        We are on Oracle 11 with Crystal Report for VS2010 Sp1.
    Thank you.
    Charles

    Have a look at the kbase below. I think this is a throwback to the fact that we can't handle the milliseconds in the DateTime. So, in order to ensure we get the correct data we search on a range plus one second of what you asked for.
    [1217417 - SQL query shows '&lt;' for a DateTime field filter although '&lt;=' was selected |http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333233313337333433313337%7D.do]

  • Manipulate Data in SQL Statement

    Hello there!
    I want to manipulate Data in a SQL Statement. For instance:
    SELECT
       name
       age
    FROM pers INTO CORROSPONDING FIELDS OF it_ppl WHERE company = '01'.
    The outcome would be something like
    Hans   25
    Sam    23
    Marie  28
    Julia  23
    So what if I want to add an column behind the selected data, where the data output should not be variable from the database but a konstant, fix value?
    I tried it like that:
    SELECT
       name
       age
       'Fix value' AS value
    FROM pers INTO CORROSPONDING FIELDS OF it_ppl WHERE company = '01'.
    Outcome should be like
    Hans   25  Fix value
    Sam    23  Fix value
    Marie  28  Fix value
    Julia  23  Fix value
    The big question is: a) Is this possible with Open SQL and if so b) how?!
    Thanks in advance,
    kind regards,
    Christof!

    Its possible through Native SQL. I have done some small modification to the standard SAP help program . Please check it.
    types: BEGIN OF ty,
            connid   TYPE spfli-connid,
            cityfrom TYPE spfli-cityfrom,
            cityto   TYPE spfli-cityto,
            text type char03,  "<---
          END OF ty.
    DATA c1 TYPE spfli-carrid VALUE 'LH'.
    data:it type table of ty,wa type ty.
    EXEC SQL PERFORMING loop_output.
      SELECT connid, cityfrom, cityto, 'abc' as text  "<---
      INTO   :wa
      FROM   spfli
      WHERE  carrid = :c1
    ENDEXEC.
    break-point. "Check the values in IT here
    FORM loop_output.
      append wa to it. "<---
    ENDFORM.

  • Passing date to another form and use the date in sql statement

    hello! to all programmers
    i have some small problem that need some help.
    i want to use date value parameter from the first page in the second page sql statement but i get invalid cursor state error so if anyone can solve this problem or give me a better solution to do this process.
    thanks in advance
    p/s
    EBDATE is define as date data type in my database.
    this is part of my jsp code...
    <---------------------------------------------------------------------->
    SimpleDateFormat sdfInput = new SimpleDateFormat( "yyyy-MM-dd" );
    SimpleDateFormat sdfOutput = new SimpleDateFormat ( "dd/MM/yyyy" );
    String date= request.getParameter("date");
    Date date1 = sdfInput.parse(date);
    Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:wtmis_db","","");
    Statement stmt=con.createStatement();
    ResultSet set=stmt.executeQuery("select * from ELECTRICBIL where EBDATE="+sdfOutput.format(date1));
    if (set!=null)
    set.next();
         Date bildate =set.getDate ("EBDATE");
         Date sdate =set.getDate ("EBSTARTDATE");
         Date edate =set.getDate ("EBENDDATE");
         int kw =set.getInt ("EBKILOWATT");
         int maxdemand =set.getInt ("EBMAXIMUMDEMAND");
         int days =set.getInt ("EBDAYS");     
    <---------------------------------------------------------------------->

    Try this
    <%
    while(set.next())
    Date bildate =set.getDate ("EBDATE");
    Date sdate =set.getDate ("EBSTARTDATE");
    Date edate =set.getDate ("EBENDDATE");
    int kw =set.getInt ("EBKILOWATT");
    int maxdemand =set.getInt ("EBMAXIMUMDEMAND");
    int days =set.getInt ("EBDAYS");
    %>
    <tr>
    <td width="211"><div align="left"><b>Bill Date :</b></div></td>
    <td width="573"><%=sdfOutput.format(date1)%></td>
    </tr>
    <tr>
    <td width="211"><div align="left"><b>Bill From :</b></div></td>
    <td width="573"> <input type="text" name="textfield" value="<%=sdate%>"></td>
    </tr>
    <tr>
    <td width="211"><div align="left"><b>Bill To :</b></div></td>
    <td width="573"> <input type="text" name="textfield2" value="<%=edate%>"></td>
    </tr>
    <tr>
    <td width="211"><div align="left"><b><b>kiloWatt Use (Rm)</b>: </b></div></td>
    <td width="573"> <input type="text" name="textfield2" value="<%=kw%>"></td>
    </tr>
    <tr>
    <td width="211"><div align="left"><b>Max Demand kiloWatt (Rm):</b></div></td>
    <td width="573"> <input type="text" name="textfield2" value="<%=maxdemand%>"></td>
    </tr>
    <tr>
    <td width="211"><div align="left"><b>Days In Billing :</b></div></td>
    <td width="573"> <input type="text" name="textfield2" value="<%=days%>"></td>
    </tr>
    <%
    %>
    i hope. Now u wouldn't get any error message...but...u wouldn't get results as well...Check ur date format with access date format....
    Revert back

  • Append a string while fetching data Through Sql Statement

    Hi i have a table which having a one field contains information of some delted files.
    when i write a sql query to fetch the information its giving out put like ..
    SELECT DISTINCT filedname  FROM TB_JOBCOMP_DBS40
    Assinid
    complte_date
    pr_date
    but i need a out put like
    Assinid -------------------->deleted
    complte_date -------------------->deleted
    pr_date -------------------->deleted
    is there any way to write sql to fetch this information

    Are you looking for concatenation ?
    SQL> select concat(ename,'----- Names Of employee') from emp
      2  WHERE rownum<3
      3  ;
    CONCAT(ENAME,'-----NAMESOFEMPLOYEE')
    SMITH----- Names Of employee
    ALLEN----- Names Of employee
    SQL> select ename||'----- Names Of employee' from emp
      2  WHERE rownum<3;
    ENAME||'-----NAMESOFEMPLOYEE'
    SMITH----- Names Of employee
    ALLEN----- Names Of employee

  • Date in SQL Statement

    Hi,
    In oracle, there is a bulit in command, sysdate to retrieve the current system date. Is there any command to retrieve current system month and year?
    Tina

    Is, TO_CHAR(SYSDATE,'YYYY-MM'), what you want ?
    /Uffe

  • Possible to do "grant" sql statement in Native SQL?

    We have a need to do a grant of access from one of our systems out for various applications.  In order for this to work we need to run a grant access command on the table and are trying to put a wrapper around this so we can use an abap.  Below is the code I am unit testing.  Two questions.  First, can a grant be done via native SQL in abap?  Second, if it can be done, what is the error with the logic where I am trying to put in the table name via a parameter.
    REPORT  ZLJTEST2.
    tables dd02l.
    DATA scarr_carrid TYPE dd02l-tabname.
    SELECT-OPTIONS s_carrid for dd02l-tabname no intervals.
    DATA s_carrid_wa LIKE LINE OF s_carrid.
    DATA name TYPE c LENGTH 20.
    TRY.
        EXEC SQL.
          CREATE FUNCTION selfunc( input CHAR(20) )
            RETURNING char(20);
            DEFINE output char(20);
            set schema sapr3;
            grant select on table input to group infouser;
            RETURN output;
            END FUNCTION;
        ENDEXEC.
        LOOP AT s_carrid INTO s_carrid_wa
                         WHERE sign = 'I' AND option = 'EQ'.
          TRY.
             EXEC SQL.
                EXECUTE PROCEDURE selfunc( IN  :s_carrid_wa-low,
                                           OUT :name )
              ENDEXEC.
              WRITE: / s_carrid_wa-low, name.
            CATCH cx_sy_native_sql_error.
              MESSAGE `Error in procedure execution` TYPE 'I'.
          ENDTRY.
        ENDLOOP.
        EXEC SQL.
          DROP FUNCTION selfunc;
        ENDEXEC.
      CATCH cx_sy_native_sql_error.
        MESSAGE `Error in procedure handling` TYPE 'I'.
    ENDTRY.

    Hi,
    Yes it is posible.
    I made one program like you want. But it need very long code.
    Here I explain the idea:
    1. Create Screen with input TEXT EDIT CONTROL.
        This is for input SQL Statement.
    2. Get SQL Statement from Text Edit Control using method <b>get_text_as_r3table</b>.
    3. Now we need to separate SQL Statement into different table.
        We Separate SELECT, FROM, WHERE, GROUP, HAVING, ORDER, etc.
    4. We need dynamic internal table to store the data.
    5. Select the data according SQL statement.
          SELECT (IT_SELECT)
            into corresponding fields of table  <dyn_table>
          FROM (IT_FROM)
          WHERE (IT_WHERE)
          GROUP BY (IT_GROUP)
          HAVING (IT_HAVING)
          ORDER BY (IT_ORDER).
    6. Display our data using ALV GRID
    Hopefully it will help you.
    Regards,

  • Executing SQL statements in container managed transactions

    I have a problem when using TopLink 9.0.3 with WebSphere 4, Oracle 9i and J2EE container managed transactions.
    The data changing SQL statements are executed at the end of the (container managed) transaction, not at the time of the calls to UnitOfWork.registerNewObjekt(),
    UnitOfWork.validate...() or UnitOfWork.commit...().
    UnitOfWork(2035008996)--validate object space.
    UnitOfWork(2035008996)--validate cache.
    UnitOfWork(2035008996)--JTS#beforeCompletion()
    UnitOfWork(2035008996)--Connection(398132708)--INSERT INTO SVM_PERSONEN (FAX, NAME, ID, [...]) VALUES ([...])
    UnitOfWork(2035008996)--JTS#afterCompletion(org.omg.CosTransactions.Status._StatusRolledBack=4)
    UnitOfWork(2035008996)--release unit of work
    But the end of the transaction is out of the application server code. The transaction ends after the invoke of the applixcation server method, as the stack trace of an occurring exception shows:
    remote exception
    javax.transaction.TransactionRolledbackException: CORBA TRANSACTION_ROLLEDBACK 0 No; nested exception is:
         org.omg.CORBA.TRANSACTION_ROLLEDBACK:
    org.omg.CORBA.TRANSACTION_ROLLEDBACK: com.ibm.websphere.csi.CSITransactionRolledbackException:
         at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:194)
         at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:67)
         at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:414)
         at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:1818)
         at de.gedas.svm.server.app.ejb.EJSRemoteStatelessNavigationEJB.findPersonenZulieferer(EJSRemoteStatelessNavigationEJB.java:964)
         at de.gedas.svm.server.app.ejb._EJSRemoteStatelessNavigationEJB_Tie._invoke(_EJSRemoteStatelessNavigationEJB_Tie.java:589)
         at com.ibm.CORBA.iiop.ExtendedServerDelegate.dispatch(ExtendedServerDelegate.java:506)
         at com.ibm.CORBA.iiop.ORB.process(ORB.java:2376)
         at com.ibm.CORBA.iiop.OrbWorker.run(OrbWorker.java:186)
         at com.ibm.ejs.oa.pool.ThreadPool$PooledWorker.run(ThreadPool.java:104)
         at com.ibm.ws.util.CachedThread.run(ThreadPool.java:137)
    So the application server code has no possiblity for special reaction to this error condition.
    How can I use TopLink to execute my SQL statement immidately, not at the the end of the transaction (which is out of the area of my code)? Only the transaction should end at the usual time, managed by the container.

    I don't think there is anyway to currently do this in a JTS managed environment, to handle the exceptions you could,
    - Make use of TopLink session ExceptionHandlers to handle the database errors during the JTS commit.
    i.e.
    uow.setExceptionHandler(yourExceptionHandler);
    or,
    - Let TopLink control the transactions instead of JTS.

  • Bulk Loading using remote sql statement execution

    Well, i have a different scenario. I want to bulk load the tables like we do in MySQL with LOAD LOCAL DATA sql command.
    I have a file populated with data, what sql statement would bulk load the data into specified table using that file?
    Adnan Memon

    In Oracle, you would either use the SQL*Loader utility to load data from a flat file or you would create an external table (9i and later) that loads the flat file.
    A quick example of the external table approach
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Wanna compare data in excel with real time signal

    Hi,
     my application is to check the PCB i/o pins... first i have to corresponding signal to every pin in GOOD PCB board and the output of each pin should saved in excel with the help of write to spreadsheet.. then the database be act as master for other PCB boards..
    If i wanna check the other pcb board means the same corresponding signals should be send to the each pin of the PCB board.. the Output received from the board should check with the data already saved in the database if it is match's means Status LED should Glow otherwise its not to glow...
    pls help me to finish this application.. i have attach model vi with post and excel too....
    Regards,
    N. Srinivasan
    Solved!
    Go to Solution.
    Attachments:
    PCB_COMPARING.vi ‏184 KB
    DATABASE.xls ‏2 KB

    The "method" you have in your last post doesn't come anywhere near to what you say you want to do.
    It creates a simulated sinewave and writes it to a text file.  Waits 1/10th of a second, reads it back from that text file, does a lot of manipulation to that data to convert it to a dynamic waveform type.  Then compares it to another simulated sinewave to say if they are equal or not.
    "My doubt is if all the received signal are saved in the excel sheet first..".  I don't know why you would doubt that this would happen.  If you receive a signal and write it to the text file, then why don't you believe it would be written to a text file?  By the way, the Read from Spreadsheet File and Write to Spreadsheet File functions have nothing to do with Excel.  They read or write data to a text file that happens to be formatted in a way (delimiters between data in a row, end of line characters between rows) that is a text file version of a spreadsheet.  Excel has the ability to import from or export to a text file, but that file is NOT an Excel file.
    You have major portions of your code missing and questions to be answered.
    Where are you actually outputing a signal to the printed circuit board?
    Where are you actually receiving a signal from the printed circuit board?
    Are you receiving one signal or 40 signals?
    What type of DAQ board are you using to do this?
    Okay, let's say once you have the first portion of your code set up to do that, you can write the data to a text file.
    Now in another part of your code, you basically repeat the procedure but instead of writing to a text file, you read the data from your "good board" text file and compare the two.
    How do you compare the signals and determine whether the newly read signal is good or bad?  Right now, you are doing a comparison for equality.  Do you think the "good" signal and the newly test signal will ever be equal?  Even if you just repeat the test on the good board, do you think those signals will be equal?  NO.  It is impossible for the signals to ever be equal, even the slightest variation in the signal is going to make them unequal.  You are never going to measure identical real world signals identically.  You need to come up with some comparison algorithm with criteria that determines whether another good signal actually matches your saved good signal, and a bad signal does not match the good signal taking into account the variations you inevitably get when measuring real world signals.
    Those are big questions you need to answer.  Assuming you work all that out, on paper in a design specification document, only then can you start worrying about the LabVIEW program and its architecture.  Ultimately, a state machine architecture will be your likely choice as you have multiple states to work with.  Initialize, test board, save data to file, read data from file, compare data, possibly more states such as wait, close program, multiple states within the test board process as it is probably a multiple step process.

  • Can we change the system date using Sql

    can we change the system date using Sql statement..
    can anyone help
    Tariq.

    There is an initialization parameter called FIXED_DATE which lets you set a fixed sysdate for testing purposes, and you can alter that date using the ALTER SYSTEM command, but as implied by the name you are setting a data/time that doesn't change. Since the normal sysdate is derived from the O/S it cannot be altered through SQL

  • SQL statement to compare dates and return boolean (yes/no)

    I am looking for a SQL statement that can compare 2 dates and return a boolean. 1 (yes) if date 1 is => date2-threshold or 0 (No) if date < date2-threshold
    Ie
    date1=20130603
    threshold=2 days
    date2=sysdate-threshold
    if [ 20130603 > sysdate-$threshold ]
    then
    return 1
    else
    return 0
    fi
    Thanks to all that answer.

    Assumming I want to get "date1" from some other table instead of from
    dual will this syntax be valid
    I was going to invoke another SQLPLUS from my shell script and pass it in
    as a variable but if I can do it on one shot it would be better.
    In addition, if "no rows" are found for date1 from the below query, would
    I need code to handle that
    with xx as
        select TO_DATE(last_date','yyyymmdd') date1, from dba_audit_table where ...;
         select TO_DATE('20130603','yyyymmdd') date1, sysdate date2  from dual;
    Thanks to all who answer
    [/code1]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • 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");

Maybe you are looking for