Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sql problem containing a " ' "

Status
Not open for further replies.

Pietjeparasietje

Programmer
Jun 13, 2005
55
NL
Hi,

I'm using the following sql statement to get a rate for a
customer. " Select * from rates where CustomerName = '''+CustomerNameStr+'''';

This statement works fine but not when I've got a customere name like this "Dinico's" the "'" is interfearing. Does anyone know how to solve this.

help is very appreciated!
Peter
 
try this:

Select * from rates where CustomerName = ' + QuotedStr(CustomerNameStr);

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual
 
Hi

In a select, quotedstr should handle an apostrophe.

Select * from rates where CustomerName = '+
Quotedstr(CustomerNameStr);

If there's still a problem with what comes back, the problem may have occurred on the insert or update, as you need to double up single apostropies - that is, you need to replace 1 apostrophy with 2 apostrophies when doing.

lou
 
You can use a query with parameters as well

Code:
SQL.Add('SELECT * FROM rates where CustomerName = :Customer');
ParamByName('Customer').AsString := sCust;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There is always another way to solve it, but I prefer my way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top