Subject Re: [firebird-support] Re: IF into SQL statement
Author Radu Sky
majstoru wrote:
> --- In firebird-support@yahoogroups.com, Radu Sky <skysword76@...>
> wrote:
>> majstoru wrote:
>>> Is there any way to put IF condition or something like that to
> prevent
>>> NUll or 0 as result into InPrice?
>>
>> CASE statements wouldn't help?
>>
>> Radu
>>
>
> Hi Radu,
>
> Sounds great if it is possible, do you have a sample or a sintax of a
> CASE into SQL script!
>
> Thanks again!
>


INSERT INTO RK (RKId, ArtId, ArtName, ArtBarcode, InPrice, OutPrice,
SpecPrice, Qty)
SELECT :ID, ArtId, ArtName, ArtBarcode, InPrice, OutPrice,

CASE
WHEN COALESCE(InPrice,0)=0 THEN <your alternate value here>
ELSE (OutPrice / InPrice) * 100
END,

Qty
FROM (SELECT ArtId, ArtName, ArtBarcode, (SELECT Price FROM QtyActual
WHERE Object = 1 AND ArtIdqty = ArtId) AS InPrice, (SELECT AVG(Price)
FROM QtyHistory WHERE Object = 1 AND ArtIdqty = ArtId) AS OutPrice,
Qty
FROM ArticleTable
WHERE ArticleTable.Id = :PARAM1)

HTH

Radu