4

I would like to simulate the effect of the following type of query (that is in Microsoft SQL Server syntax) in a Derby database. The goal is to return all records in the table where the date stored in "someColumn" is less than 7 days old. Here is the Microsoft SQL syntax for what I wish to achieve...

select * from someTable where datediff(dd, someColumn, getdate()) < 7

I have been able to determine that in Derby it will involve use of the timestampdiff function. But the syntax of the usage of functions in a WHERE clause in Derby is unknown to me and I cannot find any examples. I have found many examples where a function is used in the "what to return" clause, such as this...

select {fn timestampdiff(SQL_TSI_HOUR, startdate, enddate)} as diff

But I have not found an example of how to use such a function in a WHERE clause.

I acknowledge that my question is really "how do I use a function in a Derby WHERE clause", and yes, it's pretty basic. I also swear that I have really tried hard to find examples before posting. I hope someone can help.

John Fitzpatrick
  • 4,207
  • 7
  • 48
  • 71

1 Answers1

7

You can see an example in the original patch email,

SELECT * FROM t WHERE {fn TIMESTAMPDIFF( SQL_TSI_DAY, CURRENT_DAY, promisedDate)} <= 1
sbridges
  • 24,960
  • 4
  • 64
  • 71