Link to home
Start Free TrialLog in
Avatar of JRockFL
JRockFLFlag for United States of America

asked on

Dynamic Sort

I am trying to create a sortable query, but get this error message.
ODBC Error Code = 37000 (Syntax error or access violation)

<cfset sortby ="CASE WHEN (photo1 <> '0' AND Photo1Auth <> 1) OR (photo2 <> '0' AND Photo2Auth <> 1) OR (photo3 <> '0' AND Photo3Auth <> 1) OR (photo4 <> '0' AND Photo4Auth <> 1) OR (photo5 <> '0' AND Photo5Auth <> 1) THEN 1 ELSE 0 END DESC">

SELECT *
FROM table
ORDER BY #sortby#

If I hardcode it, it works fine

SELECT *
FROM table
ORDER BY CASE WHEN (photo1 <> '0' AND Photo1Auth <> 1) OR (photo2 <> '0' AND Photo2Auth <> 1) OR (photo3 <> '0' AND Photo3Auth <> 1) OR (photo4 <> '0' AND Photo4Auth <> 1) OR (photo5 <> '0' AND Photo5Auth <> 1) THEN 1 ELSE 0 END DESC

Any ideas??
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> Using <cfqueryparam>  
..    _instead_
Avatar of JRockFL

ASKER

_agx_

Great thinking with the cfqueryparam, I forgot all about that. It didn't work though, same results.
#PreserveSingleQuotes(sortby)# worked though.

Thank you!