温馨提示:本文翻译自stackoverflow.com,查看原文请点击:sql - search date from date time field query not working
ms-access sql vba

sql - 从日期时间字段查询中搜索日期无效

发布于 2020-04-05 00:38:17

我有以下查询

 sql_query = "select * from bericht where fromtime = " & Me.von & " and b_date = #" & Me.l_date & "#"

它通过调试打印以下行。

select * from bericht where fromtime = 6 and b_date = #1/30/2020#

在表中b_datedateTime field来自SQL Server Msaccess中的链接表

该表中存在数据,1/30/2020 2:00:00 PM其中where fromtime也为6。

为什么查询没有返回任何数据?

msaccess不能在datetime字段中搜索日期?

PS:fromtime是Intiger不是时间字段。

查看更多

提问者
Tarun. P
被浏览
55
Eric Brandt 2020-01-31 23:07

因为#1/30/2020#<> 1/30/2020 2:00:00 PM

在进行比较之前,将列转换为日期,而不是日期时间。

... and DateValue(b_date) = #" & Me.l_date & "#"

这将返回该日期之后满足您其他条件的所有行。