Solved

Delphi TQuery assistance needed with SQL

Posted on 2007-11-20
8
435 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
  • 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

Suggested Solutions

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…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 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