Subject Re: [firebird-support] Is it possible IF then statement in where clause?
Author hamacker
For any kind of logic threatment in query I think that you can use CASE/WHEN/END method (include WHERE clausule).
To make more simple your SQL, deal with null values using coalesce function, like:
where (coalesce(myvalue,-1)>0).

2017-08-30 15:19 GMT-03:00 Luigi Siciliano luigisic@... [firebird-support] <firebird-support@yahoogroups.com>:
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
--------------------------



------------------------------ ------

------------------------------ ------

++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++ ++++++

Visit http://www.firebirdsql.org and click the Documentation item
on the main (top) menu.  Try FAQ and other links from the left-side menu there.

Also search the knowledgebases at http://www.ibphoenix.com/ resources/documents/

++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++ ++++++
------------------------------ ------

Yahoo Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ firebird-support/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ firebird-support/join
    (Yahoo! ID required)

<*> To change settings via email:
    firebird-support-digest@ yahoogroups.com
    firebird-support-fullfeatured@ yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    firebird-support-unsubscribe@ yahoogroups.com

<*> Your use of Yahoo Groups is subject to:
    https://info.yahoo.com/legal/ us/yahoo/utos/terms/