?
Solved

Problem with SQL Query (TADOQuery)

Posted on 2007-10-05
11
Medium Priority
?
387 Views
Last Modified: 2010-04-05
I'm getting a Syntax error when trying to run the SQL Query with TADOQuery.

I don't know hwat I'm doing wrong. Here's the code:

ADOQuery1.SQL.Add('select * from products where (Price) <= "' + (sComboBox1.Text) + '"');

Any ideas anyone please?

Thanks

ST3VO


0
Comment
Question by:ST3VO
  • 5
  • 3
  • 3
11 Comments
 
LVL 18

Expert Comment

by:Johnjces
ID: 20022312
Try...

ADOQuery1.SQL.Add('select * from products where Price <= ' + quotedStr(sComboBox1.Text));

Is Price a text field, real or what. That could make a difference too.

John
0
 

Author Comment

by:ST3VO
ID: 20022474
Syntax error again :o/

Its a Number Field!

0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20022505
John's right, the only other thing I can think of if all of John's suggestions don't work is to put 'products' in between apostrophes e.g. 'products' (including the ''s) or adding the extension to it, e.g. 'products.db' (including the ''s)  and for the price field saying 'products.price'  (including the ''s).
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Johnjces
ID: 20022521
Stevo,

What exactly is the syntax error. Usually throws something like "unterminated string" or "syntax error near select" or something similar.

If you do a query in a separate TQuery like such as

Select * from Products where Price <= 25  (or it could be 25.00, not sure)

do you still get an error?

Heres a quick and dirty SQL tool that you can maybe more quickly test Delphi SQL ADO Code...

http://www.jcitssystems.com/SQLCheck.htm

John
0
 
LVL 13

Accepted Solution

by:
rfwoolf earned 2000 total points
ID: 20022527
ST3VO:
If it's a number field, try removing the quotedstr (i.e. you don't want '' apostrophies)
i.e.
ADOQuery1.SQL.Add('select * from products where Price <= ' +sComboBox1.Text + ';');
0
 

Author Comment

by:ST3VO
ID: 20022590
That one worked :o)

Thanks!!!

0
 
LVL 18

Expert Comment

by:Johnjces
ID: 20022605
Stevo,

Why did you have parenthesis around Price? That is why I thought it might have been a string field which you can still do comparisons on and gave you the quoted string approach.

Hmmm...

John
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 20022617
Not knowing what kind of field you are querying in your post makes it difficult to make a correct suggestion.

JJ
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20022670
Johnjces
For what it's worth, your link to the SQLcheck thing has helped me :P
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 20022728
I am glad it did!

It's just a quick and dirty little app that one can use to check their SQL code in Delphi ADO. Move cursor locations etc.

JJ
0
 

Author Comment

by:ST3VO
ID: 20023622
Hi Johnjces,

I know that your code was right too and I didn't give enough info about the fields.

I'll try to explain myself better next time!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 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