Subject Re: [firebird-support] IF into SQL statement
Author Radu Sky
majstoru wrote:
> Hi,
>
> Here is short example of my problematic SQL statement:
>
> INSERT INTO RK (RKId, ArtId, ArtName, ArtBarcode, InPrice, OutPrice,
> SpecPrice, Qty)
> SELECT :ID, ArtId, ArtName, ArtBarcode, InPrice, OutPrice, (OutPrice /
> InPrice) * 100, 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)
>
> In my client side application I set put actual Article ID to a PARAM1
> and this SQL statement returm me a values that I need, but if I get 0
> or Null as InPrice Firebird is generate an error Division by Zero!
>
> 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