Subject | Is it possible IF then statement in where clause? |
---|---|
Author | Luigi Siciliano |
Post date | 2017-08-30T18:19:33Z |
Hallo,
I have a stored procedure that have two parameters: CONTO and CLIENTE
because there is two values for CONTO that needs CLIENTE parameters, all
other values of CONTO not needs CLIENTE.
I need to have a if statement in WHERE clause to add "AND IIF
(PNC.CLIENTE_ID IS NOT NULL, PNC.CLIENTE_ID, PNC.FORNITORE_ID) =
:CLIENTE)" clause but it is not accepted, see:
I others word the "AND IIF (PNC.CLIENTE_ID IS NOT NULL, PNC.CLIENTE_ID,
PNC.FORNITORE_ID) = :CLIENTE)" will execute only for the two values of
CONTO.
< snip>
from
PN_TESTA PNT
JOIN PN_CORPO PNC on PNT.ID = PNC.PN_TESTA_ID
WHERE
PNC.CONTO_ID = :CONTO
if :CLIENTE is not null then <-- *IS NOT ACCEPTED*
AND IIF (PNC.CLIENTE_ID IS NOT NULL, PNC.CLIENTE_ID,
PNC.FORNITORE_ID) = :CLIENTE)
<snip>
There's a solution?
Thanks.
--
Luigi Siciliano
--------------------------
I have a stored procedure that have two parameters: CONTO and CLIENTE
because there is two values for CONTO that needs CLIENTE parameters, all
other values of CONTO not needs CLIENTE.
I need to have a if statement in WHERE clause to add "AND IIF
(PNC.CLIENTE_ID IS NOT NULL, PNC.CLIENTE_ID, PNC.FORNITORE_ID) =
:CLIENTE)" clause but it is not accepted, see:
I others word the "AND IIF (PNC.CLIENTE_ID IS NOT NULL, PNC.CLIENTE_ID,
PNC.FORNITORE_ID) = :CLIENTE)" will execute only for the two values of
CONTO.
< snip>
from
PN_TESTA PNT
JOIN PN_CORPO PNC on PNT.ID = PNC.PN_TESTA_ID
WHERE
PNC.CONTO_ID = :CONTO
if :CLIENTE is not null then <-- *IS NOT ACCEPTED*
AND IIF (PNC.CLIENTE_ID IS NOT NULL, PNC.CLIENTE_ID,
PNC.FORNITORE_ID) = :CLIENTE)
<snip>
There's a solution?
Thanks.
--
Luigi Siciliano
--------------------------