Subject Re: [IBO] Adding OR condition to where clause
Author Luiz Alves
Andreas,

> I 've to expand where clause:
>
> select * from table where (condition_A=1) or exists(select * from table
> where condition_A and condition_B))
>

I use it without problems:

procedure Tfrmlisguia.qr_prelfatPrepareSQL(Sender: TIB_Statement);
begin

qr_prelfat.SQLWhereItems.ADD('relfat.data>='+get_IBDateLiteral(trunc(datai.d
ate)));

qr_prelfat.SQLWhereItems.ADD('relfat.data<'+get_IBDateLiteral(trunc(dataf.da
te+1)));
if not chkPend.checked then file://não inclui pendentes
begin
qr_prelfat.SQLWhereItems.Add( 'RELFAT.PEND<>''T''');
end;
case RdRel.ItemIndex of
0:begin file://recebidas env ou nao
qr_prelfat.SQLWhereItems.Add( 'RELFAT.GUIARECEBIDA=''T''');
end;
1:begin file://recebidas e env
qr_prelfat.SQLWhereItems.Add( 'RELFAT.GUIARECEBIDA=''T''');
qr_prelfat.SQLWhereItems.Add( 'RELFAT.GUIAENVIADA=''T''');
end;
2:begin file://recebidas e não env
qr_prelfat.SQLWhereItems.Add( 'RELFAT.GUIARECEBIDA=''T''');
qr_prelfat.SQLWhereItems.Add( 'RELFAT.GUIAENVIADA<>''T''');
end;
3:begin file://env
qr_prelfat.SQLWhereItems.Add( 'RELFAT.GUIAENVIADA=''T''');
end;
4:begin file://não receb
qr_prelfat.SQLWhereItems.Add( 'RELFAT.GUIARECEBIDA<>''T''');
end;
5:begin file://fat quitadas
qr_prelfat.SQLWhereItems.Add( 'RELFAT.FAT_PAGA=''T''');
qr_prelfat.SQLWhereItems.Add( 'RELFAT.QUITADA=''T''');
end;
6:begin file://fat não pagas pelos conv
qr_prelfat.SQLWhereItems.Add( 'RELFAT.FAT_PAGA<>''T''');
end;
7:begin file://fat pagas INCOMPLETAS
qr_prelfat.SQLWhereItems.Add( 'RELFAT.QUITADA<>''T''');
qr_prelfat.SQLWhereItems.Add( 'RELFAT.FAT_PAGA=''T''');
end;
8:begin file://fat pagas INCOMPLETAS e Quitadas
file://pag incompletas
qr_prelfat.SQLWhereItems.Add( '(');
qr_prelfat.SQLWhereItems.Add( '(');
qr_prelfat.SQLWhereItems.Add( 'RELFAT.QUITADA<>''T''');
qr_prelfat.SQLWhereItems.Add( 'RELFAT.FAT_PAGA=''T''');
qr_prelfat.SQLWhereItems.Add( ')');
qr_prelfat.SQLWhereItems.Add( ' OR ');
file://quitadas
qr_prelfat.SQLWhereItems.Add( '(');
qr_prelfat.SQLWhereItems.Add( 'RELFAT.FAT_PAGA=''T''');
qr_prelfat.SQLWhereItems.Add( 'RELFAT.QUITADA=''T''');
qr_prelfat.SQLWhereItems.Add( ')');
qr_prelfat.SQLWhereItems.Add( ')');
end;
end;
if chkFisio.checked then file://não inclui Faturas da Fisio
begin
qr_prelfat.SQLWhereItems.Add( 'not exists(select 1 from fatura G where
G.nrf=relfat.nrf and G.stipo not in
(1,2,3,5,6,7,8,9,10,11,12,13,14,15,16,17))');
end;
end;


Luiz.


----- Original Message -----
From: Andreas Pohl <apohl@...>
To: <IBObjects@yahoogroups.com>
Sent: Wednesday, May 16, 2001 10:46 AM
Subject: Re: [IBO] Adding OR condition to where clause


> Jason,
>
> in an abstract form I would describe my problem as following:
>
> select * from table where condition_A=1
>
> condition_A is set by an IBO search criteria.
>
> I 've to expand where clause:
>
> select * from table where (condition_A=1) or exists(select * from table
> where condition_A and condition_B))
>
> There is a table with a treenode structure
>
> Nr , ParentNode, Name etc.
>
> 1, 0 , "1.Item"
> 2, 1 , "1.Item's sub item"
> ...
>
> If user is searching for name that fits row 2 then row 1 should be
> displayed, too, because it is the parent of row 2 (in fact condition_B of
my
> example query is an is_parent() udf).
>
> I need to add my "or" expression based on actual search criteria. Is it
> feasible?
>
> Mit freundlichem Gruss & Best Regards
>
> Andreas Pohl