Re: Aggregate SUM
Posted in 1999
Yes, you can do it since 7.3 version ( I thought so). select SUM( case col2 = "01" then col1 else 0.00 end ) from .... The 7.3 version included some function as like: NVL, CASE, DECODE, etc, what you can use to do that, but you would remember those function has a cost on performaces of the query. Another way, you could declare a store procedure and call it within select but it's expensiver to the performances. David Tucker wrote: > My question was a little more general than you thought. > > I don't need to identify nulls. I would just like know if > you can have conditions within the aggregate function SUM. > > (i.e. SUM(col1 WHERE col2 = "01") > > Thanks for your time.... though > > Brett Randall (REMOVECAPITALSbrett_s_r@hotmail.com) wrote: > : David, > > : I seem to recall tackling this problem in the distant past. > > : I assume that you are coding a standard Informix 4GL report script. If > : so, one way of achieving what you are after is to replace NULLS with > : ZEROS in the column(s) (record fields) you want to sum after the records > : are fetched from the database, but before they are passed to the > : report. That is, fetch the record, check for NULLS, and if found > : replace them with ZEROS. This will allow the sum to function properly. > > : This assumes of course that you don't need to distinguish between > : records that contain NULLS or ZEROS in those column(s). > > : HTH, > > : Brett > > : David Tucker wrote: > > : > when using the aggregste function (sum) in a report.... > : > > : > is there a way to place a conditional statemment within > : > (i.e.) > : > sum(col1 where col1 is not null)