If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Syntax error (missing operator) in query expression

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-11-03, 15:45
sgskumar sgskumar is offline
Registered User
 
Join Date: Jun 2003
Posts: 8
Syntax error (missing operator) in query expression

Hi,

I am using the following query

"select trim(name),trim(page) from [MEDICAL FACILITIES] where [name] is not null and [name] like '" & Trim(Text1.Text) & "%' order by [name]"

to select all the records that matches the name entered in the textbox-Text1.

The query works fine except when the text entered in the textbox has an " ' ". For example, when i search for "Woman's Hospital". The error i get is

Syntax error (missing operator) in query expression

Someone please tell me how I can solve this problem.

Thanks,
Suresh.
Reply With Quote
  #2 (permalink)  
Old 06-12-03, 02:23
msieben msieben is offline
Registered User
 
Join Date: Feb 2003
Location: Germany
Posts: 53
Re: Syntax error (missing operator) in query expression

Hi,

you should parse the textbox.text and duplicate any single " ' " . the sql-server will handle the " ' " as a literal-terminator, but " '' " (i.e. 2x ' ) will be handle as a literal.
Reply With Quote
  #3 (permalink)  
Old 06-12-03, 13:30
sgskumar sgskumar is offline
Registered User
 
Join Date: Jun 2003
Posts: 8
Re: Syntax error (missing operator) in query expression

Quote:
Originally posted by msieben
Hi,

you should parse the textbox.text and duplicate any single " ' " . the sql-server will handle the " ' " as a literal-terminator, but " '' " (i.e. 2x ' ) will be handle as a literal.

HI,


Thanks for your reply. But if I duplicate " ' " with double " " "(or any other character) then the text entered will not match with the data in the MSAccess database. So i will not get the correct result.

There should be some way to solve this problem.
Reply With Quote
  #4 (permalink)  
Old 06-13-03, 01:57
msieben msieben is offline
Registered User
 
Join Date: Feb 2003
Location: Germany
Posts: 53
Re: Syntax error (missing operator) in query expression

Hi,


the ( 2x ' ) will be interpreted as ONE literal '

so the text should match - give it a try, and be sure not to replace with " (one char) instead of ' plus ' (two chars).

maybe the following selects will help

-- ascii values used with char-function
select 'Double' = char(34), 'Single' = char(39)
-- direct literal , uses 2x char(39) when entered
select 'Woman''s Hospital'
-- calculated literal
select 'Woman'+char(39)+'s Hospital'
Reply With Quote
  #5 (permalink)  
Old 06-16-03, 17:14
sgskumar sgskumar is offline
Registered User
 
Join Date: Jun 2003
Posts: 8
Re: Syntax error (missing operator) in query expression

Quote:
Originally posted by msieben
Hi,


the ( 2x ' ) will be interpreted as ONE literal '

so the text should match - give it a try, and be sure not to replace with " (one char) instead of ' plus ' (two chars).

maybe the following selects will help

-- ascii values used with char-function
select 'Double' = char(34), 'Single' = char(39)
-- direct literal , uses 2x char(39) when entered
select 'Woman''s Hospital'
-- calculated literal
select 'Woman'+char(39)+'s Hospital'
Hi,


Thank you very much for the solution. It works perfect.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On