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
Solved

Delphi TQuery assistance needed with SQL

Posted on 2007-11-20
8
434 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

790 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