tried that to. didnt work and all the other types of joins
Main Topics
Browse All TopicsI'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
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
DFCRJ,
Of course they would get filtered out by your where clause.
SELECT
dbo.Customers.CustNo, dbo.Customers.Name, CAST(dbo.Customers.CustNo AS varchar(10)) + ' ' + RTRIM(dbo.Customers.Name) AS DisplayName,
SUM(dbo.Tickets.TicketTota
FROM dbo.Customers with(nolock) LEFT 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.Trans
GROUP BY dbo.Customers.CustNo, dbo.Customers.Name, CAST(dbo.Customers.CustNo AS varchar(10)) + ' ' + RTRIM(dbo.Customers.Name)
RETURN
This should improve things as it avoids filtering the customers who don't have transactions out of the results.
TimCottee
well I'll tell you. Thats almost freaking perfect. I ran it on two or three different routes and it worked when the routes had some customers with sales and customers that did not, just like i wanted. But when a route had not turned in any sales, then result set is blank. In order for it to show every customer on the route, the route must have some sales for the month. does that make any sense?
SELECT
dbo.Customers.CustNo, dbo.Customers.Name, CAST(dbo.Customers.CustNo AS varchar(10)) + ' ' + RTRIM(dbo.Customers.Name) AS DisplayName,
SUM(dbo.Tickets.TicketTota
FROM dbo.Customers with(nolock) LEFT 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
((dbo.Tickets.LocationId Is null) or
((MONTH(dbo.Tickets.Transa
(YEAR(dbo.Tickets.Transact
GROUP BY dbo.Customers.CustNo, dbo.Customers.Name, CAST(dbo.Customers.CustNo AS varchar(10)) + ' ' + RTRIM(dbo.Customers.Name)
The Tickets.LocationId can never be a NULL value. The db has to hold that value which determines the users location. I'm close to getting the results using TC's sp. below is the result.
4561319 Coast market Coast market NULL
6782223 Country market Country market NULL
4567044 Bait & tackle Bait & tackle $92.40
Business Accounts
Answer for Membership
by: TimCotteePosted on 2009-01-06 at 04:59:14ID: 23303796
Hello DFCRJ,
Make it a left join rather than an inner join. This will give you all customer records, not just those that have sales.
Regards,
TimCottee