Connecting Tech Pros Worldwide Help | Site Map

sql search and syntax errors in coldfusion search page

Newbie
 
Join Date: Mar 2007
Posts: 22
#1: Oct 26 '07
Hi Peoples

I am using sql to search for whole words in a string "listtext". on the search form my field is named "search" (without the ""'s)
to search for a whole word with a > in front of it I am using
Expand|Select|Wrap|Line Numbers
  1. OR listtext LIKE '%>#form.subject#%' 
this works all ok it seems.

HOWEVER
when i try and serach for a trailing < straight after the word like
Expand|Select|Wrap|Line Numbers
  1. OR listtext LIKE '%#form.subject#<%'
I get a syntax error when it runs

Also as soon as i add that < to the line of code the rest of the line after it changes color to blue indicating that there is something wrong with the code or there is something missing

Can anyone please help with just how i can use the sql to search for a word with a space infront of it and a < straight after it please?
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,865
#2: Oct 26 '07

re: sql search and syntax errors in coldfusion search page


This SQL statement is querying an Access database and I've been helping the OP out from the Access end.

For the purposes of Access query needs to read

Expand|Select|Wrap|Line Numbers
  1. OR listtext LIKE '%>SomeText%'
and

Expand|Select|Wrap|Line Numbers
  1. OR listtext LIKE '% SomeText<%'
The space after the first wildcard is deliberate in the second statement. Also Access would actually use * as the wildcard but I didn't want to confuse the situation.

Mary
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#3: Oct 26 '07

re: sql search and syntax errors in coldfusion search page


Quote:

Originally Posted by grabit

I get a syntax error when it runs

What's the error message?
Quote:

Originally Posted by grabit

Also as soon as i add that < to the line of code the rest of the line after it changes color to blue indicating that there is something wrong with the code or there is something missing

Are you using an editor?
Newbie
 
Join Date: Mar 2007
Posts: 22
#4: Oct 28 '07

re: sql search and syntax errors in coldfusion search page


the only error msg i get is that there is a syntax error
and yes im using dreamweaver
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#5: Oct 30 '07

re: sql search and syntax errors in coldfusion search page


I've not come across this problem before, but it seems as though < is being 'recognised' as the opening character of a tag.

Try constructing your query outside the cfquery tag as a string and then just use that variable within cfquery and see if that solves the problem.
Reply