我有一个来自查询的查询,称为 AllPosts 的查询。
AllPosts 有两个结果:
Row 1| ID: 2 PublishedDate: 2012-05-30 16:47:00.0
Row 2| ID: 3 PublishedDate: 2012-05-31 15:50:00.0
当我对名为 FilterPosts 的 AllPosts 进行查询时,使用
WHERE PublishedDate BETWEEN '2012-05-01 00:00:00' AND '2012-05-31 23:59:00'
(请注意,实际查询是为这些值执行 cfqueryparam cf_sql_date)
我希望 FilterPosts 与 AllPosts 具有相同的行,但我只得到 ID 2。如果我将 ID 2 的发布日期更改为2012-05-30 23:59:50.0
,FilterPosts 会返回正确的结果。
我也试过
WHERE PublishedDate >= '2012-05-01 00:00:00'
AND PublishedDate <= '2012-05-31 23:59:00'
5 月 31 日有一些特别奇怪的地方。
我在这里拔头发!谢谢!
我尝试从头开始构建原始查询,奇怪的是,结果相同!
<cfset test = queryNew("Name,PublishedDate", "VarChar, Time" )>
<cfset queryAddRow(test)>
<cfset querySetCell(test,"PublishedDate","2012-05-30 16:47:00.0")>
<cfset querySetCell(test,"Name","First Entry")>
<cfset queryAddRow(test)>
<cfset querySetCell(test,"PublishedDate","2012-05-31 15:47:00.0")>
<cfset querySetCell(test,"Name","Second Entry")>
<cfset StartDate = CreateDate(2012, 5, 1)>
<cfquery name="filter" dbtype="query">
SELECT Name, PublishedDate
FROM test
WHERE 1=1
AND PublishedDate >= <cfqueryparam value="#StartDate#" cfsqltype="cf_sql_date">
AND PublishedDate <= <cfqueryparam value="#DateAdd( 'n', -1, DateAdd('m', 1, StartDate) )#" cfsqltype="cf_sql_date">
</cfquery>
Filter 的结果只有“FirstEntry”,而不是两者都应该。