简体   繁体   English

访问:sql语句由于某种原因未排序

[英]access: sql statement is not sorting for some reason

my report is generating data that is supposed to be sorted by date and is within a specified date range: 我的报告正在生成应该按日期排序并且在指定日期范围内的数据:

SELECT *
FROM [lab occurrence form]
WHERE ((([lab occurrence form].[occurrence date]) Between [Forms]![Form1]![Text2] And [Forms]![Form1]![Text4]))
ORDER BY [lab occurrence form].[occurrence date] DESC;

i have two textboxes which contain the range of dates: text2 and text4 我有两个包含日期范围的文本框:text2和text4

the report is displaying the data correctly, but it is not sorting it by date 报告正确显示数据,但未按日期排序

how can i make sure that it will sort it by date? 我如何确保它将按日期排序?

i did a datasheet view on the query and it works fine, but when i run the report it does not sort it for some reason by date 我在查询上做了一个数据表视图,并且工作正常,但是当我运行报表时,由于某种原因,它没有按日期对它进行排序

Order by will sort by the field specified, but if you have not used a datetime data type, it will not sort the way you expect because it will do an alphabetical sort. Order by将按指定的字段排序,但是如果您未使用datetime数据类型,则它将不会按您期望的方式排序,因为它将进行字母排序。 The best fix for this is to stop storing dates as anything except date datatypes. 最好的解决办法是停止将日期存储为日期数据类型以外的任何内容。

Use the report's Sorting and Grouping option to establish the sort order. 使用报表的“排序和分组”选项来建立排序顺序。 In Access 2003, with the report open in design view, select "Sorting and Grouping" from the "View" menu. 在Access 2003中,报表在设计视图中打开,然后从“视图”菜单中选择“排序和分组”。 If your Access version is different, look for a similar name in the report design options. 如果您的Access版本不同,请在报告设计选项中查找类似的名称。

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

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