RSS Forums RSS
Please support our MS SQL advertiser: Programming Forums
Views: 866 | Replies: 3
Join Date: Jul 2008
Posts: 2
Reputation: chris-uk-lad is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
chris-uk-lad chris-uk-lad is offline Offline
Newbie Poster

SQL SUM problem

  #1  
Jul 22nd, 2008
Hi all!
Ive created this code to read in data from several tables but i have a problem with SUM. With this code im trying to add together all the null values that have the most recent date but all the SUM commandi have does is multiply the number by 3 :x

SELECT        A.REFNO, MAX(B.AMT), C.STATUS, C.ENDD, C.PAMT, SUM(C.PAMT)
FROM                BASIC A 
LEFT JOIN         TableB B ON B.REFNO = PD.REFNO 
AND                 A.BGROUP = B.BGROUP 
LEFT JOIN    TableC ON A.REFNO = C.REFNO
AND     A.BGROUP = PH1.BGROUP
LEFT JOIN    TableC C ON B.REFNO = PS1.REFNO
AND     A.BGROUP = C.BGROUP
WHERE A.REFNO = 'A170580' AND C.ENDD IS NULL
GROUP BY A.REFNO, C.STATUS, C.ENDD, C.PAMT 

This is the output i get, instead of adding together 961.8 and 1274.52, it just multiplys them

NULL - 961.8 - 2885.4
NULL - 1274.52 - 3823.56

All help appreciated
Last edited by chris-uk-lad : Jul 22nd, 2008 at 4:44 pm.
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 8:10 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC