Subject | IF into SQL statement |
---|---|
Author | majstoru |
Post date | 2006-04-21T21:19:25Z |
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?
This is a simple part of my SQL statement which is generate an Error,
I can't use Stored Procedure for this because I have a n user and all
of them need to see there own result, that is a reason why I'm using
SQL statement for retreivig results from server!
Thanks for HELP!
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?
This is a simple part of my SQL statement which is generate an Error,
I can't use Stored Procedure for this because I have a n user and all
of them need to see there own result, that is a reason why I'm using
SQL statement for retreivig results from server!
Thanks for HELP!