Skip to Content

Open SQL: How to Compare Timestamps?

Hi there,

I have to build a SQL statement dependant on different parameters, so using prepared statements does not make sense. So comparing dates or timestamps cannot be done via ps.setDate(i, someDate).

With this, I have tried for example to build "SELECT ID FROM MYDB WHERE SOMEDATE >= '2004-05-01 00:00:00.00'" Running this, an OpenSQLException is thrown: "type check error: operands in comparison must be compatible".

Wow! I would say, these are as compatible as they can be... Why does OpenSQL doesn't think the same about this situation?

And how can I compare dates/timestamps without using prepared statements?

Questions over questions. Would be very nice if somebody could give me some hint...

Thanks in advance


Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Jun 02, 2004 at 09:46 PM

    Did you try using a bind variable and prep statement instead?

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      To clarify - I saw you didn't want to use prep stmt initially, but there are so many benefits of using prep statements, so why invent the wheel?

      For instance:

      - It gives you a platform-independent way of executing your query from JDBC code ;

      - General automatic benefits of prep statements - stmt compiled once and can be re-used many times.

      etc. etc.


  • avatar image
    Former Member
    Jun 03, 2004 at 01:59 AM

    Hi Detlev,

    the syntax check is correct, you are comparing different types; time stamps are actually a separate type. Take a look at the <b>CONVERT DATE d TIME t INTO TIME STAMP tst TIME ZONE tz</b> command. I think this is what you're looking for.

    Best wishes, harald

    Add comment
    10|10000 characters needed characters exceeded