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

Detlev

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jun 02, 2004 at 09:46 PM

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

    Add a 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.

      -Yuri

  • author's profile photo Former Member
    Former Member
    Posted on 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 a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.