简体   繁体   English

MS Access从C ++应用程序查询ORDER BY日期

[英]MS Access query to ORDER BY date from C++ application

How does a MS Access SQL query for ordering by date looks like? 按日期排序的MS Access SQL查询的外观如何? My current query is: 我当前的查询是:

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

where strDateVal and strDateVal2 are CStrings resulting from formating ColeDateTime variables. 其中strDateValstrDateVal2是由格式化ColeDateTime变量产生的CString。 In this form i get all the dates between strDateVal and strDateVal2 (eg. 10/20/2013 and 10/25/2013), but i can't figure out a way to sort it, ascending or descending. 在这种形式下,我获得了strDateValstrDateVal2之间的所有日期(例如10/20/2013和10/25/2013),但是我不知道对它进行升序或降序排序的方法。 I've tried using 我试过使用

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

but none worked, i get an empty result. 但没有一个工作,我得到了一个空的结果。

I found the answer, and it was quite simple and silly: the correct sintax is ORDER BY Table.Field ASC . 我找到了答案,这很简单而且很愚蠢:正确的ORDER BY Table.Field ASCORDER 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 . 因此,即使您进行简单的SELECT ,也必须使用表名,就好像您要进行JOIN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM