We help IT Professionals succeed at work.
Get Started

Query binding Error when building an or statement in a where clause

onaled777
onaled777 asked
on
560 Views
Last Modified: 2012-05-09
Hi

I am trying to build a where clause so i can use cfqueryparam when getting a query to filter by certain product IDs

I get a list of productids to start with, then I try to build a where clause with OR statements and store the string in the variable ProductWhereClause

If I should print out the value for the variable ProductWhereClause, paste it into the actual query I get results and run it in SQL Server Management Studio, I get the results

If I use the variable productWhereClause in the query however, then I get an error about invalid parameter bindings.

The details are in the code snippet

Can anyone provide a solution for this?
<!--- This is how I build where clause for the products ---->

			<cfloop list="#arguments.P_ID#" index="listIndex">
				<cfset listCounter = listCounter + 1>		
				<cfset productWhereClause = productWhereClause & "p.Product_ID = <cfqueryparam value='#listIndex#' cfsqltype='cf_sql_integer'>" >
				<cfif listCounter neq ListLen(arguments.P_ID)>
					<cfset productWhereClause = productWhereClause & ' OR ' >
				</cfif>
			</cfloop>



<!--- This is how I insert it in the where clause --->


							   AND PreserveSingleQuotes(#ProductWhereClause#)


<!---This is the error that is being received--->


 	 [Macromedia][SQLServer JDBC Driver]Invalid parameter binding(s). 


<!--- This is the string that is printed out in my log file with the statement: <cflog log="application" text="#ProductWhereClause#">



AND ( p.Product_ID = <cfqueryparam value='81' cfsqltype='cf_sql_integer'> OR p.Product_ID = <cfqueryparam value='31' cfsqltype='cf_sql_integer'> OR p.Product_ID = <cfqueryparam value='34' cfsqltype='cf_sql_integer'> OR p.Product_ID = <cfqueryparam value='80' cfsqltype='cf_sql_integer'> OR p.Product_ID = <cfqueryparam value='32' cfsqltype='cf_sql_integer'> OR p.Product_ID = <cfqueryparam value='85' cfsqltype='cf_sql_integer'> )

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE