Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Include ROW only if SUM field is NOT 0.00
Tue, May 29 2012 1:40 AMPermanent Link

IQA

Hi Tim & Team,

Might be a simple one...

Is it possible in SQL to ONLY include a row in the result set IF a SUM
field is NOT 0.00

I'm producing a debtors report and I have "SUM(trans_total) AS balance"
and I only want to have the row in the result set IF the balance is NOT 0.00

Cheers,

Phil.
Tue, May 29 2012 2:59 AMPermanent Link

Uli Becker

Phil,

> Is it possible in SQL to ONLY include a row in the result set IF a SUM
> field is NOT 0.00
>
> I'm producing a debtors report and I have "SUM(trans_total) AS balance"
> and I only want to have the row in the result set IF the balance is NOT
> 0.00

select sum(trans_total) as balance from Invoices Having balance > 0

should work (untested)

Regars Uli
Tue, May 29 2012 6:13 AMPermanent Link

IQA

Thanks for the input Uli... However I'm not sure of the placement as of
the 'HAVING balance <> 0' as its used in JOIN... Any ideas?

SELECT ALL
"company"."comp_name" AS "comp_name",
"company"."city" AS "city",
"company"."state" AS "state",
"company"."companyemail" AS "companyemail",
SUM("trans_total") AS "balance"
FROM "company" LEFT OUTER JOIN "guest" ON "company"."companyID" =
"guest"."companyID"
LEFT OUTER JOIN "trans" ON "guest"."res_num" = "trans"."res_num"
WHERE "voidID" IS NULL AND "status" = 40
GROUP BY "companyID"
ORDER BY "company"."comp_name", "familyname"
Tue, May 29 2012 6:15 AMPermanent Link

IQA

It's ok I worked it out thanks again Smile
Image