navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY
Page: [1]
 
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 10:52:46   
HI GUYS
After hours of trying everything I know (not that much actually), I gave up!!
I NEED HEEEEEEEELP :):):):):):)[:' (][:' (][:' (][:' (]:)

I get error messages (syntax error) when a search is done with a keyword that contains single quote (example: keyword= o' brien). The apostrophe is messing up with the code.
Now WHAT the **** do I have to do to resolve this.

Help please:):):):):):):):):)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 12:35:56   
Hi Gege,

How are you searching for O' brien?

Are you typing the name itself manually or are you searching through a text field. Are you using a DRW?

Hisham

(in reply to Gege)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 12:42:44   
Hi,

If you are using a DRW using Frontpage

01- Insert
02- Database Results
03- Select Database > Next
04- Select the Table > Next
05- More options
06- Click Criteria > Add
07- Select the field name that has the O' Brien inside, might be LastName
08- Click OK then OK Then Next
09- Click Next
10- Click Display all records
11- Keep Add Searched form clicked and click Finish
12- Save your page
13- Browse it and type O' Brien in the search field

The SQL For that would be: (in my example I selected ContactName from customers)

SELECT * FROM Customers WHERE (ContactName = ' ::ContactName::' )

Best regards
Hisham

(in reply to Gege)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 12:54:40   
Hi again,

If you are manually typing the SQL for some reason, you have to put it this way:

SELECT CustomerID, ContactName
FROM Customers
WHERE ContactName=' o' ' brien' ;


Note that it has 4 apostrophies 1 before the O the other two are after the O and the last is after the n. Note that after the O there are two apostrophies, not one quotaion mark.

Best regards
Hisham

(in reply to Gege)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 12:56:22   
Hi,

You can also create a query in Access and selected instead of the Table in the DRW. Then search it from you form.

Regards
Hisham

(in reply to Gege)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 12:59:51   
Hi again,

In fact I am not sure how you are searching. Try putting another apostrophe after the first one.

May be you are searching a text field that required that. Anyway type the name as O' brien.

The previous steps I gave you before the manual one can search and find for O' Brien without typing an extra apostrophe.

Hisham

(in reply to Gege)
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 13:13:25   
Thanks for replying Hisham.
That works fine. :):):)
What if I want to use " LIKE" . It seens like for the script to be efficient, the keyword has to excatly match the record.
example:):

SELECT lastname, firstname, position From office WHERE lastname LIKE ' ::keyword::' OR firstname LIKE ' ::keyword::' ORDER by lastname DESC

This query works fine when you type (in the search field) a keyword with or without apostrophe. BUT, the LIKE function seems to work as a EQUAL function. Which means that if in the firstname field you have a first name such as " tommy lee" and the keyword is " tommy" , the query returns 0 records!:):):)
On the other hand, if the query looks like this:
SELECT lastname, firstname, position From office WHERE lastname LIKE ' %::keyword::%' OR firstname LIKE ' %::keyword::%' ORDER by lastname DESC
It works fine: when you type " Tommy" as a keyword (or lee) , it returns " tommy lee" as a result. HOWEVER[:j][:j], don' t try any search with a word containing an apostrophe cause it will result in " syntax error ..." :):):):)

Hope you understood what i mean (sometimes I have a hard time understanding myself[:j]
I would LOOOOOOOOOVE:):):):):) to have the best of the two which is being able to deal with the apostrophe and still be able to use the LIKE function. :)[;)

(in reply to Gege)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 13:21:50   
Hi,

This searches for O' brien with no problem:

SELECT * FROM Customers WHERE (ContactName LIKE ' %::ContactName::%' )
I tried it with a name that has an apostrophe.

This searches for the starting of the name with no problem, like your example Tommy Lee.

SELECT * FROM Customers WHERE (ContactName LIKE ' ::ContactName::%' )

Regards
Hisham

(in reply to Gege)
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 13:31:33   
Let me try it and i' ll be back.
Thanks a lot!!!!
here is my query by the way. May be i,m doing some other things wrong.
Don' t worry about the weird field names [:j] It' s french. :)

SELECT DISTINCT titre, artiste_ex, type_fichier, annee_album, genre_ex FROM extraits INNER JOIN artistes ON extraits.artiste_ex = artistes.artiste WHERE ((((titre LIKE ' %::keyword::%' ) OR (artiste_ex LIKE ' %::keyword::%' )) AND (genre_ex LIKE ' ::keyword1::' )) OR (((titre LIKE ' %::keyword::%' ) OR (artiste_ex LIKE ' %::keyword::%' )) AND (' ::keyword1::' = ' all' ))) AND (type_fichier = ' video.gif' ) ORDER BY annee_album DESC, titre ASC

What a mess!!! :):)


(in reply to Gege)
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 13:51:12   
Ok, forget about the messy script up there.

This script:
SELECT DISTINCT titre, artiste_ex, type_fichier, annee_album, genre_ex FROM extraits WHERE ((titre LIKE ' %::keyword::%' ) OR (artiste_ex LIKE ' %::keyword::%' )) AND (genre_ex LIKE ' ::keyword1::' ) OR ((titre LIKE ' %::keyword::%' ) OR (artiste_ex LIKE ' %::keyword::%' )) ORDER BY annee_album DESC, titre ASC

Give the following error message: Database Results Error
Description: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression ' ((titre LIKE ' %alek' s%' ) OR (artiste_ex LIKE ' %alek' s%' )) AND (genre_ex LIKE ' all' ) OR ((titre LIKE ' %alek' s%' ) OR (artiste_ex LIKE ' %alek' s%' ))' .
Number: -2147217900 (0x80040E14)
Source: Microsoft OLE DB Provider for ODBC Drivers

But the LIKE function works fine when I don' t use apostrophe in search:):):)

(in reply to Gege)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 13:58:29   
Hi,

Since you are using more than one table you have to use DISTINCTROW instead of DISTINCT:

SELECT DISTINCTROW Customers.CustomerID, Customers.CompanyName, Customers.ContactName, Customers.Country, Orders.EmployeeID
FROM Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID;


Since I am using two tables I like to use the tablename.fieldname in order to track what I am selecting.

Best regards
Hisham

(in reply to Gege)
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 14:17:19   
I forgot about my query for a while and did this simple query:
SELECT * FROM extraits WHERE titre LIKE ' %::keyword::%'
I got this error: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression ' titre like ' %o' brien%' ' .
Number: -2147217900 (0x80040E14)

I tried this: SELECT * FROM extraits WHERE titre LIKE ' ::keyword::%'
(record starts with keyword): this works but is not efficient

and this: SELECT * FROM extraits WHERE titre LIKE ' %::keyword::'
(record ends with record: does NOT work . gives me syntax error.

it seems like the (%) in front is the cause of the error. I' m this close (..) to give up!!:):):):):):):):):):):):):)

(in reply to Gege)
Spooky

 

Posts: 26599
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 14:20:45   
It seems you are using the FP DRW - which is strange as it normally handles apostrophes ok.
You are using that?

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to Gege)
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 14:32:16   
[:j] scuse me; what is DRW ???:)

(in reply to Gege)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 14:41:35   
Hi Gege,

I have to agree with spooky. I gave you lot of options on the top of the post and all of them worked on my DRW (Database Results Wizard) which you can create by selecting Insert/Database Results.

From your queries I suppose that you are using the DRW.

I tried the ' O' ' Brien' , Like .....% ane like %.... and like % ....% all worked just fine, I don' t know why they are not working for you. Besides as spooky noted, the DRW handles the apostrophe with no problem.

Hisham

(in reply to Gege)
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 14:54:15   
I rest my case:):):)
I' m using FrontPage 2000 DRW indeed. oh oh oh! wait a minute.

May be the problem occurs because I don' t use the search form generated by FP DRW­.
I' m creating a search form on another page using the " insert form field ..."

May be that' s why!!! let me check it out!

(in reply to Gege)
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 15:02:13   
Same problem!
:):):):):):):):):):):)

(in reply to Gege)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 15:06:28   
Ok,

Are you posting the form to the DRW page?

Create the form yourself, right click the form, select properties, Options, Action. Then in the box next to action type the path of the ASP page that hosts the DRW, let is be results.asp and try.

ELSE
You can email me the database with a few dummy records, tell me what you want and I will do it for you.

Best regards
Hisham

(in reply to Gege)
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 15:31:59   
Can' t figure out how to send database to you

(in reply to Gege)
hhammash

 

Posts: 1064
Joined: 8/19/2002
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/11/2003 15:59:35   
Hi Gege,

You can send it to this email.

hhammash@hotmail.com

This is not my forum email, but you can send it here. Send me an email through the forum when you email it.

Thanks
Hisham

(in reply to Gege)
rdouglass

 

Posts: 9228
From: Biddeford, ME USA
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/12/2003 15:15:45   
This is a well known and well documented problem. Have you seen this yet?

(in reply to Gege)
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/12/2003 19:05:07   
OK! but how do you do that in a DRW like query?

(in reply to Gege)
rdouglass

 

Posts: 9228
From: Biddeford, ME USA
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/12/2003 21:11:08   
Its actually not that bad (at least as far as I see your issue). You basically need to put the DRW on a diet and then run a Replace script wherever you need to substitute. Something like this in a DRW:

fp_sQry=" SELECT * FROM extraits WHERE titre LIKE ' %" & Replace(Request.Form(" keyword" )," ' " ," ' ' " ) & " %' "

That should take care of the apostrophe problem. Please be careful with all the apostrophes and quotes up there. It actually goes:

quote apostrophe quote comma quote apostrophe apostrophe quote

Make sense...:)

(in reply to Gege)
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/13/2003 10:49:36   
Thanks a lot. I' ll give it a try and come back to you.
Only thing is that i remember trying smthing like that before. Problem was the query was " cut" by the quotes (" ). The query made by FP DRW is between quotes (" ) and looks like s-sql = " select * ...... where .... order by ..."

Anyways. I' ll try it and give you feedback.
Thanks so much for your help

(in reply to Gege)
rdouglass

 

Posts: 9228
From: Biddeford, ME USA
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/13/2003 11:39:45   
Yup, understand about the quotes. The FP DRW uses the SQL string in quotes so it can pass the string to the DB engine. We are passing a similar string just we' re building it dynamically using Request.Form and ' massaging' it using Replace.

Make sense?

(in reply to Gege)
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/13/2003 16:52:16   
Does not work:):):):):):)
the query simply won,t accept quotes . the query is cut right after a quote. Then I get obviously a syntax error!

(in reply to Gege)
rdouglass

 

Posts: 9228
From: Biddeford, ME USA
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/14/2003 8:23:41   
quote:

the query simply won,t accept quotes . the query is cut right after a quote. Then I get obviously a syntax error!


Can you clarify for me? Are we talking about double quotes (" ) or single quotes (' )? I thought we were talking about single but I could have been mistaken....

As to the single quote issue, it does accept them in a query. Here is an exact copy of the line I sucessfully used in a test I just did...

fp_sQry=" SELECT * FROM Table1 WHERE Text LIKE ' %" & Replace(Request.Form(" Text" ), " ' " , " ' ' " ) & " %' "

In fact, I tried it by just submitting an apostrophe and it still worked. Again, are we talking single (apostrophe) or double quotes. If we' re talking single, there must be something else wrong. Can you post your code????

(in reply to Gege)
Gege

 

Posts: 13
Joined: 1/11/2003
Status: offline

 
RE: APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY - 1/18/2003 14:24:32   
Here is my code:
fp_sQry=" SELECT DISTINCT titre, artiste_ex, type_fichier, annee_album, genre_ex FROM extraits WHERE (((titre LIKE ' ::keyword::%' ) OR (artiste_ex LIKE ' ::keyword::%' )) AND (genre_ex LIKE ' ::keyword1::' )) OR (((titre LIKE ' ::keyword::%' ) OR (artiste_ex LIKE ' ::keyword::%' )) AND (' ::keyword1::' = ' all' ))) AND (type_fichier = ' video.gif' ) ORDER BY annee_album DESC, titre ASC"

The above works fine: no problem with searches involving single quotes

But, the problem is that il you are searching for let' s say " George Bush" and you type the keyword " Bush" , it won' t find it (it will find it if the keyword is " George" .
If I query ... LIKE ' %::keyword::%, a search with keyword = george (or bush) will find George Bush. BUT, any single quote in the serach will trigger " syntax error" .

That' s my problem!

PS: If I use double quotes, the query is cut as if the (" ) marks the end of the query.

thanks for looking at it.

PS2: Hammish, have you recieved my sample database?

(in reply to Gege)
Page:   [1]

All Forums >> Web Development >> ASP and Database >> APOSTROPHE CAUSING SYNTAX ERROR IN SEARCH QUERY
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts