提问人:Marek Baranko 提问时间:11/13/2023 最后编辑:Marek Baranko 更新时间:11/13/2023 访问量:51
MS Access 使用 UNION Select 查询时无法按日期范围进行筛选
MS Access Cannot filter by date range when using UNION Select query
问:
我有一个 MS Access 数据库,其中包含每个国家/地区的表格。
我创建了一个 UNION Select 查询来联接数据库中的所有表,以便我可以筛选出国家和日期并进行计算。
当我过滤一个日期时,结果是正确的。但是当我过滤日期范围时,我得到不正确的结果。日期格式似乎错误?
下面是 UNION Select 查询。我已经尝试过使用和不使用格式功能
SELECT "Argentina" as Country, Format([Argentina - Immediate Refund].[Date sent], "Short Date") As [Date sent], [Argentina - Immediate Refund].[Received date], [Argentina - Immediate Refund].[Released date], [Argentina - Immediate Refund].[Processed Forms] FROM [Argentina - Immediate Refund]
UNION ALL SELECT "Austria" as Country, Format([Austria - Immediate Refund].[Date sent], "Short Date") As [Date sent], [Austria - Immediate Refund].[Received date], [Austria - Immediate Refund].[Released date], [Austria - Immediate Refund].[Processed Forms] FROM [Austria - Immediate Refund];
这是我筛选从 2023 年 1 月 10 日到 2023 年 1 月 11 日的日期时的结果截图
我尝试在SQL语句中更改日期格式
答:
1赞
Gustav
11/13/2023
#1
删除日期值的格式:
SELECT
"Argentina" as Country,
[Date sent],
[Received date],
[Released date],
[Processed Forms]
FROM
[Argentina - Immediate Refund]
UNION ALL
SELECT
"Austria" as Country,
[Date sent],
[Received date],
[Released date],
[Processed Forms]
FROM
[Austria - Immediate Refund];
要将文本日期转换为真实日期值,请执行以下操作:
"Argentina" as Country,
CVDate([Date sent]) As DateSent,
CVDate([Received date]) As ReceivedDate,
CVDate([Released date]) As ReleasedDate,
[Processed Forms]
评论
0赞
Marek Baranko
11/13/2023
在我最初的查询中,我没有日期值的任何格式,所以我已经尝试过了。我刚才添加了格式,看看它是否有帮助,但它没有改变任何东西
1赞
Gustav
11/13/2023
Format 返回文本,因此无法对这些值进行排序。日期字段的数据类型必须为日期。否则使用(接受 Null 值)进行转换,如下所示。CVDate
0赞
iDevlop
11/14/2023
同意,但为什么要使用 CVDate 而不是 CDAte ?你得到一个变体,它可能比约会效率低。啊,也许是为了处理空值?
0赞
Gustav
11/14/2023
@iDevlop:是的,对于可能的 Null 值。
评论