troubleshooting Question

Show All Customers in Grid

Avatar of DFCRJ
DFCRJFlag for United States of America asked on
Microsoft SQL Server 2005
8 Comments1 Solution225 ViewsLast Modified:
I've got a grid that shows a routes customers MTD sales, the only problem I have encountered and didnt think about is, if a customer doesnt have any sales for the month it appears the route has zero customers. If a route has 25 customers and only 15 have MTD sales, I still need to show all customers in the grid. I've tried a few different things but cant get the results I need. Below is my stored procedure. Thanks for the help

SELECT   
  dbo.Customers.CustNo, dbo.Customers.Name, CAST(dbo.Customers.CustNo AS varchar(10)) + ' ' + RTRIM(dbo.Customers.Name) AS DisplayName,
SUM(dbo.Tickets.TicketTotal) AS MTD
FROM   dbo.Customers with(nolock) INNER JOIN
dbo.Tickets with(nolock)  ON dbo.Customers.LocationId = dbo.Tickets.LocationId AND dbo.Customers.CustNo = dbo.Tickets.CustNo
 WHERE     (dbo.Customers.RouteNo = @RouteNo) AND (dbo.Customers.LocationId = @LocationId) AND (MONTH(dbo.Tickets.TransactionDate)  = MONTH(GETDATE())) AND (YEAR(dbo.Tickets.TransactionDate) = YEAR(GETDATE())) 
GROUP BY dbo.Customers.CustNo, dbo.Customers.Name, CAST(dbo.Customers.CustNo AS varchar(10)) + ' ' + RTRIM(dbo.Customers.Name)
RETURN
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros