0

按日期排序的 MS Access SQL 查询是什么样的?我目前的查询是:

newVal.Format(_T("SELECT * FROM Table WHERE (CDATE(DateStart) BETWEEN #%s# AND #%s#) "), strDateVal, strDateVal2);

其中strDateValstrDateVal2是由格式化 ColeDateTime 变量产生的 CStrings。在这种形式中,我得到了和之间的所有日期strDateValstrDateVal2例如 2013 年 10 月 20 日和 2013 年 10 月 25 日),但我想不出一种方法来对其进行排序,升序或降序。我试过使用

ORDER BY DateStart ASC
ORDER BY=([DateStart] ASC)
ORDER BY (CDATE(DateStart)) ASC

但没有一个工作,我得到一个空的结果。

4

1 回答 1

1

I found the answer, and it was quite simple and silly: the correct sintax is ORDER BY Table.Field ASC. So you have to use the table name even if you make a simple SELECT, as if you would make a JOIN.

于 2013-11-03T22:01:18.030 回答