On 27 Sep 2006, at 06:56, Juan Pablo Garcia wrote:

Hi:

I want do do a query based on the value of several controls on a search window. How must I do the nesting of queries? Suppose I have 3 checkboxes and I want to find the records whose values are equal to "checkbox 1 ticked" OR "checkbox 2 ticked" AND also the ones that have certain text in another column.

My problem is that I can´t figure out how to deal with empty or not ticked vaues. If I´m sure I will have at least one value selected on the searchwindow interface, it is simpler. But how can I manage the issues when some of my "areas of search" are empty?


Your best bet is to build the SQL query string yourself, adding where claus bit by bit, and where appropriate test the length of the controls text before including it:

dim SelectStr, FromStr, WhereStr as String

SelectStr = "select a.Field1, b.Field2"

FromStr = " from tabA as a join tabB as b on a.Field1 = b.Field1"

WhereStr = " where 1 = 1"

if len(trim(EditField1.Text)) > 0 then
  WhereStr = " and a.Field2 = '" + trim(EditField1.Text) + "'"
end if

if len(trim(EditField2.Text)) > 0 then
  WhereStr = " and a.Field4 like '%" + trim(EditField4.Text) + "%'"
end if

Then run your query etc.

--
Ian M. Jones
___________________________________
http://www.imijsoft.com
http://www.ianmjones.net (blog)


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to