Subject Re: Boolean Expression in parameter
Author rogervellacott
Here is a rather verbose trick you can use within the query to get a
boolean result

SELECT F1, F2, (SELECT COUNT(*) FROM RDB$DATABASE WHERE A = B) AS
BRESULT FROM MY_TABLE

The expression A = B can be as complicated as you like, including
selects from other tables. If the expression is true, BRESULT will
be 1. If it is false, BRESULT will be 0. Use RDB$DATABASE because it
is guaranteed to have only one record.

Here is an example, to convert positive numbers to negatives
depending on whether they are credits or debits

SELECT T.TRANSACTION_VALUE * (1 - (2 * (SELECT COUNT(*) FROM
RDB$DATABASE
WHERE T.DEBIT_OR_CREDIT = 'CRN'))) FROM MY_TABLE.T

Roger Vellacott
Passfield Data Systems

--- In ib-support@y..., "Edson T. Marques" <marques@o...> wrote:
> Hi;
>
> I don't know how can I explain my problem in English (it is bad!
(in Enghish I can read but write nor speak)), so I'll try to
communicate using signals! Sorry!
>
> I know this is not possible(!), but I want to know if there are any
other way (some secret not published) to do this?
>
> CREATE PROCEDURE IIF (EXPRESSION INTEGER, TRUE INTEGER, FALSE
INTEGER)
> RETURNS (RET INTEGER)
> AS
> BEGIN
> IF (EXPRESSION) THEN
> RET = TRUE;
> ELSE
> RET = FALSE;
>
> SUSPEND;
> END
>
> where I coud use in something like this:
>
> select Ret from IIF('A' = 'B', 0, 1) returns 1
> select Ret from IIF('A' = 'A', 0, 1) returns 0
> etc...
>
> thank you very much!
>
>
> [Non-text portions of this message have been removed]