本文介绍了我怎样才能按日期排序在MS Access 2007?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道我怎么排序文本列,显示日期格式mm / dd / YYYY数据。

Just want to know how do I sort a text column that shows data in date format mm/dd/yyyy.

推荐答案

您必须首先转换为日期以获得适当的排序。这是将Datetext到RealDate,然后排序在该列(字段)的查询。您也可以点击标题,选择排序顺序。

You will first have to convert to a date to get a proper sort. This is a query that converts Datetext to RealDate, and then sorts on that column (field). You can also click the header to choose the sort order.

SELECT 
   t.ID, 
   t.Datetext, 
   DateSerial(Mid([Datetext],InStrRev([Datetext],"/")+1),
              Mid([Datetext],1,InStr([Datetext],"/")-1),
              Mid([Datetext],InStr([Datetext],"/")+1,
                 (InStrRev(Datetext,"/")-InStr([Datetext],"/"))-1)) AS RealDate
FROM Table t
Order By 3

您可以使用IIF避免零错误:

You can use IIf to avoid errors from null:

IIf([Datetext] Is Null,Null,DateSerial(
           Mid([Datetext],InStrRev([Datetext],"/")+1),
           Mid([Datetext],1,InStr([Datetext],"/")-1),
           Mid([Datetext],InStr([Datetext],"/")+1,
              (InStrRev(Datetext,"/")-InStr([Datetext],"/"))-1))) AS RealDate

这篇关于我怎样才能按日期排序在MS Access 2007?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 19:38