How to locate a string containing a euro-sign €

Hi,

I'm trying to locate a string in a table.
MyString := 'Test € 50';
Query1.Locate('Name', MyString,[]);

This doesn't find the record even though it exists.
Is there any other way to do this?
Stef MerlijnDeveloperAsked:
Who is Participating?
 
jimyXCommented:
Use SQL query.
To find exact match:
MyString := 'Test € 50';
Query1.SQL.Text := 'Select Name from Table1 where Name = '+QuotedStr(MyString);
Query1.Open;

To find all records that contain the euro-sign:
MyString := '€';
Query1.SQL.Text := 'Select Name from Table1 where Name like '+QuotedStr(MyString);
Query1.Open;
0
 
fromerCommented:
Query1.Filtered := False;
Query1.Filter := 'Name = ' + QuotedStr(MyString);
Query1.Filtered := True;

check Query1.RecordCount > 0...

But your code should work...
check your sql...
0
 
Stef MerlijnDeveloperAuthor Commented:
This works just fine. Thank you
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Geert GOracle dbaCommented:
What database type is it ?
And what character set does it use.

For instance if it's oracle and your character set is ISO8859CP1,
it can look like it is in the database, but it's not actually there ... :)
The iso charset does not contain the Euro symbol (ASCII 120)

If this is the case, the databasecharacterset must be changed to WE8MSWIN1252
0
 
Geert GOracle dbaCommented:
jymiX ... parameters ... parameters ... parameters  ?
0
 
KoenVandemoortelCommented:
In some SQL versions, it's
Select Name from Table1 where Name = '%€%'

So, in Delphi:
Query1.SQL.Text := 'Select Name from Table1 where Name like '''%€%''';
 
0
 
Geert GOracle dbaCommented:
use parameters !
it wil get correctly translated

Query1.SQL.TExt := 'SELECT NAME FROM TABLE1 WHERE NAME LIKE :PARAM';
Query1.ParamByName('PARAM').AsString := '%€%';
Query1.Open;
0
 
Stef MerlijnDeveloperAuthor Commented:
Yes the parameter-part needs to be added to the SQL.
And I needed an exact search (so without %%).

Thank you all for the other suggestions.
0
 
Geert GOracle dbaCommented:
if you can't find your record, first use the %%, next starting narrowing your search

check case sensitivity

where upper(name) like :param

ParamByName('PARAM').AsString := UpperCase('SearchString');
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.