Subject Re: [firebird-support] Re: where field = any
Author Alexandre Benson Smith
Miroslav Penchev wrote:

>Yes, but the real situation is slightly different. James has a SQL
>statement like this one:
>
>SELECT *
> FROM ATable T
>WHERE (1=:ACTIVEFILTER_NAME OR T.ANAME LIKE :CUST_NAME) AND
> (1=:ACTIVEFILTER_CITY OR T.CITY LIKE :CUST_CITY) AND
> .....
>
>in User Interface James has several check-boxes with edits and user can
>filter data by different combination of fields and values. I am right
>James?
>
>So - you cannot supply different SELECT statements for every combination
>of selected fields to filter.
>
>Cheers,
>
>
If this is the case, just make it on the fly:

procedure MakeFilter;

procedure AddWhere(var aWhere:String const aCondition:string);
begin
if aWhere <> '' then
aWhere := aWhere + ' and ';

aWhere := aWhere + aCondition;
end;

var
wSQL, wWhere:String;

begin
wSQL := 'Select * from aTable';

wWhere := '';

if CheckBoxName.Checked then
AddWhere(wWhere, 'Name = ''blablabla''')

if CheckBoxCity.Checked then
AddWhere(wWhere, 'City = ''blablabla''')

....

if wWhere <> '' then
wSQL := wSQL + ' where ' + wWhere;

MyQuery.SQL.Text := wSQL;
MyQuery.Open;
...
end;

If it will be dynamic, just make it dynamic.

Just be carefull for table aliases and ambiguous column names if you
will do joins (or use views instead).

see you !

--

Alexandre Benson Smith
Development
THOR Software e Comercial Ltda.
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br