Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Delphi TQuery assistance needed with SQL

Posted on 2007-11-20
Medium Priority
Last Modified: 2012-05-05
Hi experts,

I need a bit of help with an SQL query.

Here is what I have now:

ADOQuery1.SQL.Add('select * from Table where (Field1) = "' + (ComboBox1.Text) + '"');

That's fine BUT I need to do a query with more than 1 comboxBox

For example:

Select * From Table where Field1 = ComboBox1.text AND ComboBox2.text

Hope you see what I'm trying to do.


Question by:ST3VO
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 13

Expert Comment

ID: 20318687
First of all I hope you know about the QuotedStr function, then you can do something like this:

ADOQuery1.SQL.Add('Select * from Table where (Field1) = ' + Quotedstr(Combobox1.text + ' ' + Combobox2.text);

If your comboboxs had this text:
Combobox1: 'FORD' and
Combobox2: 'Fiesta'
this would be the result
Select & From Table where (Field1) = 'FORD Fiesta'

Expert Comment

ID: 20318772
Also, if you're trying to match records where "Field1" is the same as the text of both comboboxes, then either... (a) compare the values of the CBs first (much faster) or (b) format your query as

SELECT * FROM Table WHERE (Fiield1 = that) AND (Field2 = this)

Good luck!

Author Comment

ID: 20319947
I cannot get the Syntax right!

I need to copare 2 fields.

Select * from table where field1=comboxbox1.text AND field2 = comboxBox2.text

I cannot figure out how to put it all together with the + " ' etc...

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!


Author Comment

ID: 20319991
Actualy it's:

Select * from table where field1=comboxbox1.text AND field2 CONTAINS comboxBox2.text
LVL 13

Expert Comment

ID: 20320131
You can TRY this. To do partial matches you use the LIKE operator, and the wildcard is %. So I am trying LIKE %SOMETHING%

'Select * from Table where (Field1) = ' + Quotedstr(Combobox1.text + ' AND ((Field2) LIKE "%' + Combobox2.text + '%)'

LVL 13

Expert Comment

ID: 20320154
'Select * from Table where (Field1) = ' 
+ Quotedstr(Combobox1.text) // 'FORD'
+ ' AND ((Field2) LIKE "%'  // AND ((Field 2 LIKE %
+ Combobox2.text  //Fiesta
+ '%)' // %)

Open in new window

LVL 13

Accepted Solution

rfwoolf earned 2000 total points
ID: 20320204
Oh darn, almost got it! Spotted another error! Here goes again:
'Select * from Table where (Field1) = ' 
+ Quotedstr(Combobox1.text) // 'FORD'
+ ' AND ((Field2) LIKE "%'  // AND ((Field 2 LIKE "%
+ Combobox2.text            //Fiesta
+ '%")'                     // %")

Open in new window


Author Closing Comment

ID: 31410087

Thanks a million!

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

715 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