我有一个在加载页面时返回零记录的查询。如果我将相同的查询(从调试输出)复制并粘贴到navicat,我会得到返回的行(如我所料)。有人见过这个吗?它发生在本地 (CF9) 和远程在我们的登台服务器 (CF10) 上。更奇怪的是,这是一个以前运行良好的查询 - 我只是在 where 子句中添加了一个 if 语句,然后突然......
这是查询:
SELECT
a.EncounterProductID,
a.DateTime AS ServiceDate,
aa.CartItemID,
aaa.CartID,
aaaaa.CartStatus,
b.ProductID,
b.ProductName,
b.CPTCode,
b.Price,
c.EncounterID,
c.DateTimeClosed AS EncounterClosedDate,
d.FirstName,
d.LastName
FROM
EncounterProducts a
LEFT JOIN CartItemProduct aa ON (a.EncounterProductID = aa.EncounterProductID AND aa.Active = 1)
LEFT JOIN CartItem aaa ON (aa.CartItemID = aaa.CartItemID)
LEFT JOIN Cart aaaa ON (aaa.CartID = aaaa.CartID)
LEFT JOIN CartStatus aaaaa ON (aaaa.CartStatusID = aaaaa.CartStatusID),
Product b,
Encounters c,
Contacts d,
EncounterStatuses e
WHERE
1 = 1
AND (aa.CartItemID IS NULL OR aaaaa.CartStatus = 'Deleted')
AND a.Active = 1
AND a.ProductID = b.ProductID
AND a.EncounterID = c.EncounterID
AND c.PatientID = d.ContactID
AND c.EncounterStatusID = e.EncounterStatusID
AND e.EncounterStatus = 'Closed'
<CFIF IsDefined("ARGUMENTS.encounter") AND IsObject(ARGUMENTS.encounter)>
AND c.EncounterID = <CFQUERYPARAM cfsqltype="cf_sql_integer" value="#ARGUMENTS.encounter.getID()#">
<CFELSE>
AND c.DateTimeClosed >= <CFQUERYPARAM cfsqltype="cf_sql_date" value="#ARGUMENTS.startDate#">
AND c.DateTimeClosed < <CFQUERYPARAM cfsqltype="cf_sql_date" value="#DateFormat(DateAdd('d', 1, ARGUMENTS.endDate), 'yyyy-mm-dd')# 00:00:00">
</CFIF>
AND c.LocationID = <CFQUERYPARAM cfsqltype="cf_sql_integer" value="#ARGUMENTS.locationID#">
AND c.CustomerID = <CFQUERYPARAM cfsqltype="cf_sql_integer" value="#ARGUMENTS.customerID#">
</CFQUERY>
在我添加这些行之前,所有这些都工作得很好:
<CFIF IsDefined("ARGUMENTS.encounter") AND IsObject(ARGUMENTS.encounter)>
AND c.EncounterID = <CFQUERYPARAM cfsqltype="cf_sql_integer" value="#ARGUMENTS.encounter.getID()#">
<CFELSE>
AND c.DateTimeClosed >= <CFQUERYPARAM cfsqltype="cf_sql_date" value="#ARGUMENTS.startDate#">
AND c.DateTimeClosed < <CFQUERYPARAM cfsqltype="cf_sql_date" value="#DateFormat(DateAdd('d', 1, ARGUMENTS.endDate), 'yyyy-mm-dd')# 00:00:00">
</CFIF>
以前,它只是:
AND c.DateTimeClosed >= <CFQUERYPARAM cfsqltype="cf_sql_date" value="#ARGUMENTS.startDate#">
AND c.DateTimeClosed < <CFQUERYPARAM cfsqltype="cf_sql_date" value="#DateFormat(DateAdd('d', 1, ARGUMENTS.endDate), 'yyyy-mm-dd')# 00:00:00">
没有 IF/ELSE 语句。
以前有人见过这样的事情吗?有任何想法吗?
谢谢。