Subject | RE: [firebird-support] Result type in calculated fields |
---|---|
Author | Svein Erling Tysvær |
Post date | 2007-10-11T11:18:40Z |
You wrote:
...
(((COl3 * sum(col2)/(col4 +0.0001))
...
I've never tried multiplying/dividing the sum of one column with other columns, but I suppose it could work if you group by Col3 and Col4. But let's say Col4 = 0. That means you multiply Col3 and sum(col2) and then multiply again by 10000 (by dividing by 0.0001). Sounds like something easily overflowing.
You haven't said which version you are using, but if it is Firebird 1.5 or higher, I'd rather recommend a statement like:
Case when NOT (col4 = 0) then (col3 * sum(col2)/col4) else NULL end as MyOutputColumn
The result will of course be very different if col4 is 0, but NULL (unknown) to me sounds like a better answer when dividing by 0.
This answer is just an addition to what Helen wrote, take heed to her recommendation to use CAST as well.
HTH,
Set
...
(((COl3 * sum(col2)/(col4 +0.0001))
...
I've never tried multiplying/dividing the sum of one column with other columns, but I suppose it could work if you group by Col3 and Col4. But let's say Col4 = 0. That means you multiply Col3 and sum(col2) and then multiply again by 10000 (by dividing by 0.0001). Sounds like something easily overflowing.
You haven't said which version you are using, but if it is Firebird 1.5 or higher, I'd rather recommend a statement like:
Case when NOT (col4 = 0) then (col3 * sum(col2)/col4) else NULL end as MyOutputColumn
The result will of course be very different if col4 is 0, but NULL (unknown) to me sounds like a better answer when dividing by 0.
This answer is just an addition to what Helen wrote, take heed to her recommendation to use CAST as well.
HTH,
Set