Re: SQL IF

From: Maciej Zoltowski <mzoltowski_at_eragsm.com.pl>
Date: 2000/06/12
Message-ID: <642A954DD517D411B20C00508BCF23B00125674D_at_mail.sauder.com>#1/1


Greg wrote:
>
> If I have the SQL code
>
> if (variable1 <> variable2) then....
>
> Works if the Variables have a value
> but if one of them is null, it doesn't.
>
> how to include the case one of the variables are null in the statement.
>
> thanks Greg

You can use nvl() function, e.g.
if (nvl(variable1, null_value1) <> nvl(variable2, null_value2)) then...

but it works only if domains of variables allow you to specify valid null_values not included in their domains.

More generic approach is:
if (((variable1 is not null) and (variable2 is not null) and (variable1 <> variable2)) or

    ((variable1 is null) and (variable2 is not null)) or     ((variable1 is not null) and (variable2 is null))) then

Regards
Maciek Received on Mon Jun 12 2000 - 00:00:00 CEST

Original text of this message