Advantage 中的时间比较 SQL

Time comparison in Advantage SQL

正在尝试在优势查询中进行时间比较。未能在 Advantage 文档中找到答案。看起来应该很简单。

Table定义为:

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

基于 this book on google books 我想我应该能够对这样表达的文字进行比较:

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

但这会抛出

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

您应该始终使用 TIME'HH:MM:SS' (24h) 或 TIME'HH:MM:SS am' (12h) 文字格式:

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

我认为您遇到了 2124 错误,因为您使用的是大写 am/pm 表示法或者因为您没有使用前导零。

另请参阅:

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

来自 SQL 文字下的文档(在 ADS 帮助文件中,在 Advantage 开发人员指南下,第二部分 - Advantage SQL,第 11 章 - Advantage 简介SQL, SQL 文字)

Time literals are enclosed in single quotation marks, and use one of the following four formats: HH:MM, HH:MM AM (or PM), HH:MM:SS, or HH:MM:SS AM (or PM). If the AM (or PM) is missing from the literal, 24-hour time is assumed. The AM/PM part of time literals is not case sensitive. The following are valid time literals:

'19:10'
'4:43 AM'
'9:00:45 pm'
'22:19:59'

使用这个 table 定义和数据:

create table #temp (ID AutoInc,
                    Dt Date,
                    Tm Time);

insert into #temp (Dt, Tm) values (CurDate() - 1, CurTime());
-- Wait to make sure time changes slightly
insert into #temp (Dt, Tm) values (CurDate(), CurTime());

select * from #temp;

/* Output:
    ID   Dt           Tm        
    --   ----------   -----------
    1    02/26/2015   11:50:22 AM 
    2    02/27/2015   11:51:02 AM
*/

以下查询根据正确的时间成功检索到正确的行(当然,请调整到适合您的数据的时间):

select * from #temp where Tm = '11:50:22 AM'

使用 ARC32 针对具有本机 ADT table 类型的 Advantage 10.10 进行测试。