SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SUM not working????


SUM not working????

Author
Message
mutlyp
mutlyp
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 88
RiderID_PK| StartDate | EndDate | RouteID_FK| Expr1| FriDate| Total|
27 | 10/14/2004 | 5/23/2010 | 107| 107| 1/15/2010| 28.8|
29 | 10/14/2004| NULL | 107| 107| 1/15/2010| 17.28|
32 | 10/14/2004| 3/14/2010 | 107| 107| 1/15/2010| 28.8|
33 | 10/14/2004| NULL | 107| 107| 1/15/2010| 23.04|
35 | 10/14/2004| NULL | 107| 107| 1/15/2010| 17.28|
36 | 10/14/2004| 5/2/2010 | 107| 107| 1/15/2010| 28.8|
780 | 7/8/2006 | NULL | 107| 107| 1/15/2010| 28.8|
1178 | 4/22/2007 | NULL | 107| 107| 1/15/2010| 28.8|
1272 | 7/8/2007 | NULL | 107| 107| 1/15/2010| 28.8|
1661 | 2/1/2009 | 5/2/2010 | 107| 107| 1/15/2010| 28.8|
1851 | 10/11/2009| NULL | 107| 107| 1/15/2010| 28.8|
1852 | 10/11/2009| 9/19/2010 | 107| 107| 1/15/2010| 28.8|


Those are the result I get when I run this query:
SELECT Rider.RiderID_PK, Rider.StartDate, Rider.EndDate, Rider.RouteID_FK, Rider.RouteID_FK AS Expr1, RiderFareHistory.FriDate,
SUM(RiderFareHistory.AmountPaid) AS Total
FROM Rider INNER JOIN
RiderFareHistory ON Rider.RiderID_PK = RiderFareHistory.RiderID_FK
WHERE (RiderFareHistory.FriDate = CONVERT(DATETIME, '2010-01-15 00:00:00', 102)) AND (Rider.RouteID_FK = '107') AND
(Rider.EndDate > CONVERT(DATETIME, '2010-01-15 00:00:00', 102) OR
Rider.EndDate IS NULL) AND (Rider.StartDate < CONVERT(DATETIME, '2010-01-15 00:00:00', 102))
GROUP BY Rider.RiderID_PK, Rider.RouteID_FK, RiderFareHistory.FriDate, Rider.EndDate, Rider.StartDate

I need to SUM all the values in the AmountPaid Column.
What am I doing wrong????

Sorry for the formatting. I attatched a photo of the query and the results.
Thank You
MutlyP
Attachments
QueryResults.bmp (5 views, 768.00 KB)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search