We help IT Professionals succeed at work.

Problem with SQL Query (TADOQuery)

ST3VO
ST3VO asked
on
402 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


Comment
Watch Question

Commented:
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

Author

Commented:
Syntax error again :o/

Its a Number Field!

Commented:
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).

Commented:
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
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
That one worked :o)

Thanks!!!

Commented:
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

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

JJ

Commented:
Johnjces
For what it's worth, your link to the SQLcheck thing has helped me :P

Commented:
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

Author

Commented:
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!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.