Subject RE: [firebird-support] IF into SQL statement
Author Paul Mercea
You can use coalesce (value, 0) !

Paul M

-----Original Message-----
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of majstoru
Sent: Saturday, April 22, 2006 12:19 AM
To: firebird-support@yahoogroups.com
Subject: [firebird-support] IF into SQL statement

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!






++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Visit http://firebird.sourceforge.net and click the Resources item
on the main (top) menu. Try Knowledgebase and FAQ links !

Also search the knowledgebases at http://www.ibphoenix.com

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Yahoo! Groups Links