Subject Re: [firebird-support] use of SUM
Author Ivan Cruz
Sudheer Palaparambil wrote:

>Hi,
>
> How to SUM the line_discount on line no.2 ?
>
>1. SELECT S.bill_no, S.discount, SUM( SD.line_value ),
>2. SUM( ( SD.line_value * SD.discount_p ) / 100 ) AS line_discount
>3. FROM sale S LEFT JOIN sale_det sd ON ( SD.company_id = S.company_id )
>4. AND ( SD.parent_id = S.id )
>5. WHERE ( ( S.company_id = :dCID ) AND ( S.entry_date = :dAsOn ) )
>
> Is this the correct way to sum ? Or should I use SUM for individual column
>
>
>
Yes. But don't forget to...

GROUP BY S.bill_no, S.discount

> like this ?
>
> ( SUM( SD.line_value ) * SUM( SD.discount_p ) ) / 100 AS line_discount
>
>
>
No. It makes no sense to me.

> Since I am populating all numeric fields to non-null values, I am not
> bothered about checking for NULL values here.
>
>
>

Ivan Cruz