Can I use IF in regular statements (not PSQL) ?
You cannot use IF, but you can use CASE instead (which is almost the same). Here's an example with employee database:
SELECT PO_NUMBER, ORDER_DATE, case when PAID = 'y' then 'PAID' else 'NOT PAID' end, TOTAL_VALUE
FROM SALES;
CASE is introduced in Firebird 1.5.
If you need more complex expressions that are not possible with CASE, and still need to do it in a single statement, you can use EXECUTE BLOCK with Firebird 2 and above.
Also, you can use IIF (Firebird 2). For example:
SELECT PO_NUMBER, ORDER_DATE, iif(PAID = 'y', 'PAID', 'NOT PAID'), TOTAL_VALUE
FROM SALES;
Do you find this FAQ incorrect or incomplete? Please e-mail us what
needs to be changed. To ensure quality, each change is checked by our editors (and often tested on live Firebird
databases), before it enters the main FAQ database. If you desire so, the
changes will be credited to your name. To learn more, visit our add content page.
All contents are copyright © 2007-2024 FirebirdFAQ.org unless otherwise stated in the text.