Subject | Re: [firebird-support] SUM and null values |
---|---|
Author | Martijn Tonies |
Post date | 2011-11-25T11:12:20Z |
Hi,
cycles through the results of your query and sums the WEIGHT, breaking
when it hits NULL and returning NULL then.
With regards,
Martijn Tonies
Upscene Productions
http://www.upscene.com
Download Database Workbench for Oracle, MS SQL Server, Sybase SQL
Anywhere, MySQL, InterBase, NexusDB and Firebird!
> How can I get NULL from SUM when a value is NULL?I guess you have to create a Selectable Stored Procedure for it that
>
> I know that aggregate functions only use non null values.
> My problem is different. I want to sum a list of values, but if one or
> more is null, then I would need to get NULL.
>
> For example, table person:
>
> Name, Weight
> -----,----
> John, 50
> Paul, 100
> Mary, NULL
>
>
> If I do "SELECT SUM(Weight) FROM Persons", I get 150.
> I would like to get NULL since we do not know the weight of Mary, and then
> it is not possible to get the total weight.
> How can I do it?
cycles through the results of your query and sums the WEIGHT, breaking
when it hits NULL and returning NULL then.
With regards,
Martijn Tonies
Upscene Productions
http://www.upscene.com
Download Database Workbench for Oracle, MS SQL Server, Sybase SQL
Anywhere, MySQL, InterBase, NexusDB and Firebird!