我傳遞三個整數到一個函數在CFC,像這樣:CFQUERYPARAM ColdFusion中不工作10
<cfscript>
Q = TOPBIKES.GetTopBikes(127, 10, 11);
writeDump(Q);
</cfscript>
的CFC使用這些整數來運行這樣的查詢:
<!--- GET TOP BIKES --->
<cffunction name="GetTopBikes">
<cfargument name="FeatureID" required="true">
<cfargument name="MinWins" required="true">
<cfargument name="RecordsToReturn" required="true">
<cfscript>
LOCAL.FeatureID = ARGUMENTS.FeatureID;
LOCAL.MinWins = ARGUMENTS.MinWins;
LOCAL.RecordsToReturn = ARGUMENTS.RecordsToReturn;
</cfscript>
<!--- RUN QUERY --->
<cfquery name="Q">
SELECT TOP #LOCAL.RecordsToReturn#
B.BikeID,
B.BikeName,
BS.PCTWins
FROM Bikes B
LEFT JOIN BikeScores BS
ON B.BikeID = BS.BikeID
WHERE BS.Wins > <cfqueryparam cfsqltype="cf_sql_integer" value="#LOCAL.MinWins#">
AND B.BikeID IN ( SELECT BikeID
FROM Bikes_Features
WHERE FeatureID = <cfqueryparam cfsqltype="cf_sql_integer" value="#LOCAL.FeatureID#">
)
ORDER BY BS.PCTWins desc
</cfquery>
<cfreturn Q>
</cffunction>
問題是我無法讓cfqueryparam在SQL語句的頂部工作。
這些工作:
SELECT TOP 11
SELECT TOP #LOCAL.RecordsToReturn#
這不起作用:
SELECT TOP <cfqueryparam
cfsqltype="cf_sql_integer"
value="#LOCAL.RecordsToReturn#">
我可以,但是用其他任何地方查詢。我知道這是一個整數,並在其他地方使用時用於替換FeatureID。
有關爲什麼CFQUERYPARAM不在TOP中工作的任何線索?
FWIW,您應該將type =「numeric」添加到您的CFARGUMENT中,因爲您無法使用CFQUERYPARAM。 –