Solved

Delphi TQuery assistance needed with SQL

Posted on 2007-11-20
8
431 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
 

Author Comment

by:ST3VO
ID: 20319991
Actualy it's:

Select * from table where field1=comboxbox1.text AND field2 CONTAINS comboxBox2.text
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now