Groups | Blog | Home
all groups > sql server mseq > may 2007 >

sql server mseq : Filtering out zeros


Tom
5/21/2007 9:42:01 AM
Running a query that adds up certain fields in our database and where
applicable returns a zero total. Looking for a way to return only those
lines that are not zero value.

I'm new to this SQL thing, have experience in Access but am tripped up on
Tom
5/21/2007 10:27:00 AM
Sorry Russell.. Here is the code I'm working with. We want the "Total" field
to not show zeros..

SELECT b.code, sv.Reference, sv.DateCreated, SUM(svt.TransactionValue) as
Total from stored_value as sv
join stored_value_transaction as svt on sv.id = svt.FKStoredValueID and
svt.recorddeleted = 0
join customer_order as co on co.id = sv.FKCustomerOrderID and
co.recorddeleted = '0'
join branch as b on b.id = co.fkbranchid and b.recorddeleted = '0'
where sv.FKPaymentMethodID = '7' and sv.recorddeleted = '0' GROUP BY
b.code, sv.reference, sv.DateCreated Order By b.code, sv.reference

[quoted text, click to view]
Russell Fields
5/21/2007 1:16:22 PM
Tom,

A piece of sample code or a little more explanation would help. I assume
you do not mean:

SELECT AccountCode, AccountValue
FROM AccountTable
WHERE AccountValue <> 0

Perhaps you mean:

SELECT AccountCode, SUM(AccountValue) AS TotalValue
FROM AccountTable
GROUP BY AccountCode
HAVING SUM(AccountValue) <> 0

RLF

[quoted text, click to view]

Russell Fields
5/21/2007 2:01:57 PM
Tom,

That is what I was illustrating as follows:

SELECT b.code, sv.Reference, sv.DateCreated,
SUM(svt.TransactionValue) as Total
from stored_value as sv
join stored_value_transaction as svt
on sv.id = svt.FKStoredValueID
and svt.recorddeleted = 0
join customer_order as co
on co.id = sv.FKCustomerOrderID
and co.recorddeleted = '0'
join branch as b
on b.id = co.fkbranchid
and b.recorddeleted = '0'
where sv.FKPaymentMethodID = '7' and sv.recorddeleted = '0'
GROUP BY b.code, sv.reference, sv.DateCreated
HAVING SUM(svt.TransactionValue) <> 0 -- Eliminate zero sums
Order By b.code, sv.reference

RLF
[quoted text, click to view]

AddThis Social Bookmark Button