"Invalid Column" on multiple where clauses with subqueries and cfqueryparam
I'm seeing a behavior in the coldfusion cfquery that I'd like to find an exmplanation for . I've got a query that does a subquery in the select portion and if I have multiple where lines, I get an "invalid column name" message for my second where clause, but only when I'm using cfqueryparam
For example on the following I get "Invalid column name 'position_id'"
SELECT department_staff_tbl.*,
( SELECT max(bookmark_id)
FROM bookmarked_items_tbl
WHERE item_id = department_staff_tbl.staff_id
) AS bookmark_id
FROM department_staff_tbl
WHERE department_id = <cfqueryparam value="#arguments.deptid#" cfsqltype="cf_sql_integer">
AND position_id = <cfqueryparam value="#arguments.posid#" cfsqltype="cf_sql_integer">
AND staff_id = <cfqueryparam value="#arguments.staffid#" cfsqltype="cf_sql_integer">
If I change the order of my where clause so staff_id is first, then it tells me "department_id" is an invalid column.
If I only have one where clause, it works. (i.e. WHERE position_id = <cfqueryparam value="#arguments.posid#" cfsqltype="cf_sql_integer">).
If I remove the where clause from my subquery (WHERE item_id = department_staff_tbl.staff_id) it works.
It also works if I remove the cfqueryparam from my where clause so that my query looks like this:
SELECT department_staff_tbl.*,
( SELECT max(bookmark_id)
FROM bookmarked_items_tbl
WHERE item_id = department_staff_tbl.staff_id
) AS bookmark_id
FROM department_staff_tbl
WHERE department_id = #arguments.deptid#
AND position_id = #arguments.posid#
AND staff_id = #arguments.staffid#
Any thoughts?
