Need help using sum in a SQL query

Hi Experts,
I have a table in my SQL Server 2008 db that holds payment records. My table currently stores about 250,000 records.  Some of the columns in my table are PaymentType, PaymentCode, and PaymentAmount.  I want to get a sum of the PaymentAmount based on the various PaymentType and PaymentCode groupings. Do I need to use a Case Statement?  How can I accomplish this?  Below is a sample of the raw data, and what I want the out should be.  Thanks in advance.

Raw Data Sample:
PaymentType      PaymentCode      PaymentAmount
CR            PD            $10.00            
CR            FI            $35.12
CR            FI            $23.99
CR            PD            $25.20
CR            PD            $20.00      
CR            PD            $35.00      
HE            CH            $40.00
HE            CH            $15.00


RESULT SHOULD BE:
PaymentType      PaymentCode      Total            
CR            FI            $59.11
CR            PD            $90.20
HE            CH            $55.00

Thank you,
mrotor
mainrotorAsked:
Who is Participating?
 
Ron MalmsteadConnect With a Mentor Information Services ManagerCommented:
SELECT PaymentType ,     PaymentCode,     SUM(PaymentAmount) as PaymentTotal
FROM YourTableName
GROUP BY PaymentType, PaymentCode


..try that.
0
 
Simone BConnect With a Mentor Senior E-Commerce AnalystCommented:
Try this:

SELECT PaymentType, PaymentCode, Sum(PaymentAmount) as Total
from PaymentRecordsTable
Group by PaymentType, PaymentCode

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.