Solved

Delphi TQuery assistance needed with SQL

Posted on 2007-11-20
8
436 Views
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.

Thanks

ST3VO
0
Comment
Question by:ST3VO
[X]
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
8 Comments
 
LVL 13

Expert Comment

by:rfwoolf
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'
0
 
LVL 4

Expert Comment

by:kenpem
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!
0
 

Author Comment

by:ST3VO
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...

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!

 

Author Comment

by:ST3VO
ID: 20319991
Actualy it's:

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

Expert Comment

by:rfwoolf
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%

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

0
 
LVL 13

Expert Comment

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

Open in new window

0
 
LVL 13

Accepted Solution

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

Open in new window

0
 

Author Closing Comment

by:ST3VO
ID: 31410087
Perfect!!!

Thanks a million!
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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 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