我有这个在我的PHP代码中执行的查询:
SELECT ((SUM(CASE WHEN I.InCompliance=1 AND FI.Status='C' THEN 1 ELSE 0 END)*100) / (SUM(CASE WHEN FI.Status='C' THEN 1 ELSE 0 END))) as result
FROM tbl_Inspection I,tbl_Facility F,tbl_FacilityInspection FI
WHERE I.InspectionDate >= '2013-2-01'
AND I.InspectionDate < '2014-3-01'
AND I.belongsToFacility=F.FacilityID
AND I.FacInspId=FI.FacInspId
AND F.DistrictID=1
它在mssql管理工作室中对我执行得很好,但是我收到了这个错误
警告:odbc_exec():SQL错误:[unixODBC] [FreeTDS] [SQL Server]未声明游标。在/srv/www/htdocs/capsdev/includes/phpdbform_db_odbc.php中的SQLExecDirect中的SQL状态37000第104行SELECT((SUM(CASE WHEN I.InCompliance = 1 AND FI.Status ='C'THEN 1 ELSE 0 END)* 100)/(SUM(FI.Status ='C'那么1 ELSE 0 END) ))作为结果从tbl_Inspection I,tbl_Facility F,tbl_FacilityInspection FI WHERE I.InspectionDate&gt; ='2013-2-01'AND I.InspectionDate&lt; '2014-3-01'AND I.belongsToFacility = F.FacilityID AND I.FacInspId = FI.FacInspId AND F.DistrictID = 1警告:odbc_fetch_array()要求参数1为资源,在/ srv / www / htdocs中给出布尔值第114行/capsdev/includes/phpdbform_db_odbc.php
非常感谢任何帮助。
谢谢,
丹尼尔
答案 0 :(得分:1)
尝试使用显式连接而不是隐式连接。
类似的东西:
SELECT ((SUM(CASE WHEN I.InCompliance=1 AND FI.Status='C' THEN 1 ELSE 0 END)*100) / (SUM(CASE WHEN FI.Status='C' THEN 1 ELSE 0 END))) as result
FROM tbl_Inspection I
inner join tbl_Facility F
on I.belongsToFacility=F.FacilityID
inner join tbl_FacilityInspection FI
on I.FacInspId=FI.FacInspId
WHERE I.InspectionDate >= '2013-2-01'
AND I.InspectionDate < '2014-3-01'
AND F.DistrictID=1