Question

Sow ALL entries.

Asked by: J_K_M_A_N

I have a two tables like so:

Table1: CustInfo
    CustID - Primary Key
    Name

Table2: OrderInfo
    OrderNumber - Primary Key
    Date
    Amount
    CustID

I want to sum all the amounts from the orderinfo grouped by custID which I can do just fine. What I am having a problem with is showing ALL custID's even if there are no amounts or orders for them. I have the relationship set up to show all custid's and only those with matches in orderinfo but it doesn't work.

Please help.

J_K_M_A_N

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-03-28 at 08:25:56ID21792110
Tags

sow

,

work

Topic

Microsoft Access Database

Participating Experts
4
Points
500
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. 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.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. UPDATE value in table1 with value from joined table2
    I have a 2 tables that can be joined by two reference fields - table1 and table2 have a 1-to-many relationship. I want to sum values in table2 and update the corresponding total value in table 1. The following SQL illustrates what I am attempting but is doesn't work as Acce...
  2. Table1 table2 results from one that are not in the othner
    I have table1 and table2 I want all the results of table1 that are not in table2 MYSQL4.x Syntax. Thanks! Randy
  3. Select where table1 not in table2
    I have 2 tables. Table1 is made of 2 primary keys, table_id and job_id along with a bunch of other values (lets just use job_name for now). Table2 is made of 2 primary keys, table_id and job_id along with a bunch of other values (Don't care what for this example). I need to...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

by: jimhornPosted on 2006-03-28 at 08:30:31ID: 16312002

Select blah blah blah
FROM CustInfo
LEFT JOIN OrderInfo ON CustInfo.blah = OrderInfo.blah

The left join guarantees that all records in CustInfo are returned, even if there's no related OrderInfo records.

Hope this helps.
-Jim

 

by: josephwalshPosted on 2006-03-28 at 08:30:35ID: 16312003

This is an example similar to what you might do

SELECT tblARCustomer.strCustomerID, Sum(tblOEOrder.curOrderTotal) AS SumOfcurOrderTotal
FROM tblOEOrder RIGHT JOIN tblARCustomer ON tblOEOrder.strCustomerID = tblARCustomer.strCustomerID
GROUP BY tblARCustomer.strCustomerID

 

by: GRayLPosted on 2006-03-28 at 08:35:54ID: 16312067

I guess it depends on whether you are left or right handed;-)

 

by: jimhornPosted on 2006-03-28 at 08:37:40ID: 16312082

Ray - You kill me. :)

 

by: Joe_CoolPosted on 2006-03-28 at 08:37:42ID: 16312083

try this

SELECT [Cust info].[Cust name], [order info].*
FROM [Cust info] LEFT JOIN [order info] ON [Cust info].[Cust num] = [order info].[cust num];


It should give you all of the cust info data and all of the order data as well.

 

by: J_K_M_A_NPosted on 2006-03-28 at 08:51:35ID: 16312239

At the risk of being told that my table SUCKS (which I have already been told) here is my SQL statement.

SELECT Child.Name, (Sum([10A50]+[10A100]+[10A250]+[10A500]+[10A1000])) AS [3/8 Pipe], (Sum([15A50]+[15A100]+[15A250]+[15A500]+[15A1000])) AS [1/2 Pipe], (Sum([20A50]+[20A100]+[20A180]+[20A250]+[20A500])) AS [3/4 Pipe], (Sum([25A50]+[25A100]+[25A180]+[25A250])) AS [1 Pipe], (Sum([32A50]+[32A100]+[32A250])) AS [1-1/4 Pipe], (Sum([38A50]+[38A100]+[38A150])) AS [1-1/2 Pipe], (Sum([50A50]+[50A100]+[50A150])) AS [2 Pipe], Sum(Orders.Value) AS DollarValue
FROM Child LEFT JOIN Orders ON Child.ChildID = Orders.ChildID
WHERE (((Orders.Date) Between #3/1/2006# And #3/24/2006#))
GROUP BY Child.Name
ORDER BY Child.Name;

And it does NOT return all 57 names in the Child table. I am not sure why. Maybe because of the sums I am doing? I don't know. I am guessing it is beacuse of the WHERE with the dates. I am guessing it doesn't like that. Is there a way around it?

J_K_M_A_N

 

by: J_K_M_A_NPosted on 2006-03-28 at 08:53:53ID: 16312261

I took out the WHERE line and it returns all but for ALL of the data. Is there a way to get just the dates I want and still LEFT JOIN?

J_K_M_A_N

 

by: GRayLPosted on 2006-03-28 at 09:02:38ID: 16312361

Change:

WHERE (((Orders.Date) Between #3/1/2006# And #3/24/2006#))

To:

WHERE (Orders.Date Between #3/1/2006# And #3/24/2006#) OR IsNull(Orders.Date)

 

by: J_K_M_A_NPosted on 2006-03-28 at 09:06:15ID: 16312417

That only added 2 entries that have NO order data at all.

J_K_M_A_N

 

by: GRayLPosted on 2006-03-28 at 11:19:15ID: 16313824

Maybe I'm missing something, but if some of the Child.Names do not have any orders and you use date criteria in the WHERE clause, how can you expect to see them, unless you include the IsNull() criterion?  Are you saying there are more than 2 Names missing?  Can you give us an example of what is missing?  I just noticed you use the word Date as a field - that is a no-no as Date is an Access Reserved Word.  If you absolutely have to use it, it must be wrapped in square brackets.

Orders.[Date]

 

by: J_K_M_A_NPosted on 2006-03-28 at 11:29:40ID: 16313927

Well, the orders table holds all the data for the past year+. I want to show all customers and the totals of a certain month. I was hoping to do that with one SQL statement. It looks like I will not be able to do that. Some of the customers have data in the table but not that are between the dates I put in. I would like to see all of their totals (even if they are 0) for all customers. Does that explain it better?

J_K_M_A_N

 

by: GRayLPosted on 2006-03-28 at 11:47:25ID: 16314090

OK, the two customers that were added were the only two missing or were there more?  Try this query.  I have included a parameters criteria which includes the year as you said the table contains all the data for the past year+.  You should also qualify all the fields in the sum() functions with their table name:

SELECT Child.Name, (Sum([10A50]+[10A100]+[10A250]+[10A500]+[10A1000])) AS [3/8 Pipe], (Sum([15A50]+[15A100]+[15A250]+[15A500]+[15A1000])) AS [1/2 Pipe], (Sum([20A50]+[20A100]+[20A180]+[20A250]+[20A500])) AS [3/4 Pipe], (Sum([25A50]+[25A100]+[25A180]+[25A250])) AS [1 Pipe], (Sum([32A50]+[32A100]+[32A250])) AS [1-1/4 Pipe], (Sum([38A50]+[38A100]+[38A150])) AS [1-1/2 Pipe], (Sum([50A50]+[50A100]+[50A150])) AS [2 Pipe], Sum(Orders.Value) AS DollarValue
FROM Child LEFT JOIN Orders ON Child.ChildID = Orders.ChildID
WHERE Format(Orders.[Date],"yym") = [Enter Year and  Month Number (yym)] OR IsNull(Orders.[Date])
GROUP BY Child.Name
ORDER BY Child.Name;

 

by: J_K_M_A_NPosted on 2006-03-28 at 12:15:39ID: 16314421

Let me give you some sample data:

Table Orders:
Date              ChildID  10A50   10A100   10A250   10A500   10A1000   Value  (There is more but this will do for an example)
02/25/2006        2         100      200          0              0             0        $3400
02/18/2006        3          50       300         0              0              0        $1700
03/27/2006        2          50        100         0              0             0        $2300
03/15/2006        1          50         0           250          500           0       $2700
03/18/2006        2          50        100         0              0            1000   $3500


Now what I want is a list like the one below using the query where I can tell it what dates I want. In this case, I want all of March 2006 so I would like to see something like this:

ChildID    10A50   10A100   10A250   10A500   10A1000   Value
   1            50          0            250        500          0         $2700
   2           100        200           0            0          1000      $5800
   3             0           0              0          0            0          $0

ChildID 3 would be zero because that sale was in Feburary. ChildID 1 and 2 would sum the fields together but only for the month of march. Is there a way to do that?


J_K_M_A_N

 

by: J_K_M_A_NPosted on 2006-03-28 at 12:16:42ID: 16314437

I have inreased the value to 500 and I should also mention, I am actually using VB6. I am just trying to get it to work in Access first and then I am going to transfer it to VB6. Thanks everyone.

J_K_M_A_N

 

by: GRayLPosted on 2006-03-28 at 12:32:46ID: 16314590

If it is a case of seeing zeros instead of a blank, try:

SELECT Child.Name,
Nz(Sum([10A50]+[10A100]+[10A250]+[10A500]+[10A1000]),0) AS [3/8 Pipe],  Nz(Sum([15A50]+[15A100]+[15A250]+[15A500]+[15A1000]),0) AS [1/2 Pipe],  Nz(Sum([20A50]+[20A100]+[20A180]+[20A250]+[20A500]),0) AS [3/4 Pipe],
Nz(Sum([25A50]+[25A100]+[25A180]+[25A250]),0) AS [1 Pipe],0),
Nz(Sum([32A50]+[32A100]+[32A250]),0) AS [1-1/4 Pipe],
Nz(Sum([38A50]+[38A100]+[38A150]),0) AS [1-1/2 Pipe],  
Nz(Sum([50A50]+[50A100]+[50A150]),0) AS [2 Pipe],
Format(Nz(Sum(Orders.Value),0),"Currency") AS DollarValue
FROM Child LEFT JOIN Orders ON Child.ChildID = Orders.ChildID
WHERE Format(Orders.[Date],"yym") = [Enter Year and  Month Number (yym)] OR IsNull(Orders.[Date])
GROUP BY Child.Name
ORDER BY Child.Name;

 

by: J_K_M_A_NPosted on 2006-03-28 at 12:38:18ID: 16314637

The blank would be fine but I don't get that. Not for ALL of the customers. I am going to give out the points and give up. I really don't know what I am doing and I need to find a good book on the subject. I have the program written without using a database and it works ok. I will just stick with that and stop trying to learn database programming for now. It is driving me crazy. Thanks for all of your attempts.

J_K_M_A_N

 

by: GRayLPosted on 2006-03-28 at 13:53:50ID: 16315386

Thanks, but I sure hate to leave it like this.  

 

by: J_K_M_A_NPosted on 2006-03-28 at 14:57:36ID: 16316001

Well, I don't either but I really need a book and/or some examples to learn from. I think I am trying to jump in TOO deep to start. That makes it a little hard to keep your sanity. :)

Thanks anyway for the help.

J_K_M_A_N

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...