Search code examples
sqladvantage-database-server

Time comparison in Advantage SQL


Trying to do a time comparison in an advantage query. Haven't been able to find the answer in the Advantage documentation. Seems like it should be very simple.

Table definition is:

CREATE TABLE TBL ( 
      ID AutoInc,
      Date Date,
      [T] Time
)

Based on this book on google books I figured I should be able to just do a comparison against a literal expressed like this:

SELECT * FROM TBL WHERE [T] > '9:00:00 AM'

But that throws

Error 7200:  AQE Error:  State = S0000;   NativeError = 2124;  [iAnywhere Solutions][Advantage SQL Engine]Invalid operand for operator: > [Invalid TIME] -- Location of error in the SQL statement is: 27

Solution

  • You should always use the TIME'HH:MM:SS' (24h) or TIME'HH:MM:SS am' (12h) literal format:

    SELECT * FROM TBL WHERE [T] > TIME'09:00:00 am'
    

    I think you get the 2124 error, because you are using either upper case am/pm notation or because you did not use a leading zero.

    See also:

    http://devzone.advantagedatabase.com/dz/webhelp/advantage11/master_sql_literals.htm