Connecting Tech Pros Worldwide Forums | Help | Site Map

SQL SUM Questions

Mike
Guest
 
Posts: n/a
#1: Nov 13 '05
I am using the follwoing SQL query:

SELECT RECID, PATNUMBER, Sum(amount) As Amount
FROM PAT_Transactions
Group By recid, patnumber
Having patnumber = 374757 AND recid = 'C'
Order By patnumber

My problem is that there are rows that have a a negative amount. I want to
add only the positive amount rows together. This query adds all the rows for
each patient number positive and negitive to give me the total.

How do I tell SQL to add only the positive row amounts together?

Thanks in advance!!

Mike



jj
Guest
 
Posts: n/a
#2: Nov 13 '05

re: SQL SUM Questions


Hi Mike

Put in Where amount > 0

SELECT RECID, PATNUMBER, Sum(amount) As Amount
FROM PAT_Transactions
WHERE Amount>0
Group By recid, patnumber
Having patnumber = 374757 AND recid = 'C'
Order By patnumber

/JJ

"Mike" <noway@forgetit.com> skrev i en meddelelse
news:k7vaf.8995$Lv.1269@newssvr24.news.prodigy.net ...[color=blue]
>I am using the follwoing SQL query:
>
> SELECT RECID, PATNUMBER, Sum(amount) As Amount
> FROM PAT_Transactions
> Group By recid, patnumber
> Having patnumber = 374757 AND recid = 'C'
> Order By patnumber
>
> My problem is that there are rows that have a a negative amount. I want to
> add only the positive amount rows together. This query adds all the rows
> for each patient number positive and negitive to give me the total.
>
> How do I tell SQL to add only the positive row amounts together?
>
> Thanks in advance!!
>
> Mike
>
>[/color]


modialsi
Guest
 
Posts: n/a
#3: Nov 13 '05

re: SQL SUM Questions


where amount > 0 ?

Closed Thread


Similar Microsoft Access / VBA bytes