How to rephase statement for use in SQL from MS Access in Delphi

Posted on 2006-04-24
Medium Priority
Last Modified: 2010-04-05
I have a statement that is being used for MS Access in Delphi. However, as I need to upgrade the database to SQL, I am not sure how to reconstruct the statement. The statement that is being used for MS Access is:

SQL.Add('Select * From table1, table2 Where field1 Like ' + ' "' + Text1.text + '*' + '" ');

The statement run when a entry is entered into the text box and it will look up the SQL database and show only the refined results.

Any help is appreciated.
Question by:cwtang
LVL 11

Accepted Solution

pcsentinel earned 1000 total points
ID: 16522905
Just Replace the * with a % sign


the SQL ends up looking like

 SELECT * FROM table1 WHERE Field1 LIKE "Fred%"
To find all instances starting with Fred


 SELECT * FROM table1 WHERE Field1 LIKE "%Fred%"
To find all instances containing Fred


 SELECT * FROM table1 WHERE Field1 LIKE "%Fred"
To find all instances ending in Fred

LVL 22

Assisted Solution

by:Mohammed Nasman
Mohammed Nasman earned 600 total points
ID: 16523031
as pcsentinel said, replace * with %

also you need to correct the quoations in your statement

so your statement will look like

SQL.Add('Select * From table1, table2 Where field1 Like ' + QuotedStr(Text1.text + '%');

Assisted Solution

saravananvg earned 400 total points
ID: 16523459
Hello sir,

  it should be as follows

SQL.Add('Select * from table1,table2 where Field1 like '''+Text1.Text+'%''');

with regards,

Author Comment

ID: 16532748
Thanks everyone. Got it working :)

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question