Forum Moderators: coopster & phranque

Message Too Old, No Replies

SQL Syntax error

Getting an error with CFQUERY

         

justa

5:28 am on Feb 25, 2002 (gmt 0)

10+ Year Member



I'm getting the below error when I try to search the database. The only syntax on line 9:2 to 9:41 is

<CFQUERY NAME="movies" DATASOURCE="ows">

Can anyone explain?????

"Error Diagnostic Information
ODBC Error Code = 37000 (Syntax error or access violation)

[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'MovieTitle LIKE '%a%' WHERE PitchText LIKE '%a%' WHERE RatingID = 3'.

The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (9:2) to (9:41)."

The Results page query looks like this ....

<CFQUERY NAME="movies" DATASOURCE="ows">
SELECT MovieTitle, PitchText, Summary, DateInTheaters
FROM Films


<!--- Search by Movie Title --->
<CFIF FORM.MovieTitle IS NOT " ">
WHERE MovieTitle LIKE '%#MovieTitle#%'
</CFIF>

<!--- Search by Pitch Text --->
<CFIF FORM.PitchText IS NOT " ">
WHERE PitchText LIKE '%#FORM.PitchText#%'
</CFIF>

<!--- Search by Rating ID --->
<CFIF FORM.RatingID IS NOT " ">
WHERE RatingID = #FORM.RatingID#
</CFIF>
ORDER BY MovieTitle
</CFQUERY>

justa

11:22 pm on Feb 25, 2002 (gmt 0)

10+ Year Member



If anyone is interested I managed to find the answer.

You are only allowed one WHERE clause (so simple yet I over looked it 50 times).

This is the code I ended up with. This is one solution, altough I'd be interested to hear if anyone has an alternative (cleaner) way to get these results.

<CFQUERY NAME="movies" DATASOURCE="ows">
SELECT MovieTitle, PitchText, Summary, DateInTheaters
FROM Films

WHERE 0=0
<!--- Search by Movie Title --->
<CFIF FORM.MovieTitle IS NOT " ">
AND MovieTitle LIKE '%#MovieTitle#%'
</CFIF>

<!--- Search by Pitch Text --->
<CFIF FORM.PitchText IS NOT " ">
AND PitchText LIKE '%#FORM.PitchText#%'
</CFIF>

<!--- Search by Rating ID --->
<CFIF FORM.RatingID IS NOT " ">
AND RatingID = #FORM.RatingID#
</CFIF>
ORDER BY MovieTitle
</CFQUERY>