简体   繁体   中英

MS Access query to ORDER BY date from C++ application

How does a MS Access SQL query for ordering by date looks like? 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. 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. 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 . So you have to use the table name even if you make a simple SELECT , as if you would make a JOIN .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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