Results 1 to 7 of 7
  1. #1
    George is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    295

    Summing one field value to another

    Good morning,

    I have 2 field in a table - CourseMarks and ExamMarks. I am making a query to sum these two values. My code entered through the expression builder is Total: [CourseMarks]+[ExamMarks].

    When the query is run there are no results if both fields have a score, but If there is a score in the CourseMarks field and none in the ExamMarks field the CourseMark is returned.

    Is there an explanation for this problem?

    All the field value data types are interger.



    Thanks for any assistance.

    George

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    What is the data type for each field?
    Can you post the SQL code of your query?

  3. #3
    George is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    295

    Summing fields

    This is my SQL code. The data types are integer


    SELECT [last Name] & " " & [First Name] AS Name, Programs.[Prog Name], Courses.[Course Name], Attendance.CourseMark, Attendance.ExamMark, [Class by Course].Location, Attendance.Atten, [Class by Course].Group, [CourseMark]+[ExamMark] AS Total
    FROM Courses INNER JOIN (Programs INNER JOIN (Student INNER JOIN ([Class by Course] INNER JOIN Attendance ON [Class by Course].ClassbyCourseID = Attendance.[Class by course ID]) ON Student.[Student ID] = Attendance.StudentID) ON Programs.[Program Code] = [Class by Course].[Program Code]) ON Courses.[Course ID] = [Class by Course].[Course ID];

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I have 2 field in a table - CourseMarks and ExamMarks.
    Kind of misleading here. You are not working with one table, but rather with many tables. Without seeing the structure of your data tables (and maybe some data), it can be difficult to know exactly where you may be having issues. However, here are a few details with may help:

    1. Do not use reserved words like "Name" and "Group" as field names. It could cause confusion/issues/errors. For a list of reserved words, see here: http://support.microsoft.com/kb/286335

    2. When you are performing INNER JOINS between multiple tables, it will ONLY return records where there are matches in every table. So if a certain value is missing from one of your tables, it will not be part of your final data set. I would recommend determining which table has the complete list of records you want to return, and then use this table in LEFT JOINS with your other tables in order to return all records. You can use the NZ function to return 0 or something else in place of all the NULL values you get in the non-matched values. See this for details on joins: http://office.microsoft.com/en-us/ac...010096320.aspx

    If you still cannot figure it out, please post some small data samples from your data, and the expected results (note that screen prints work best for me, as I cannot download files from my current location).

  5. #5
    George is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    295

    Summing Fields

    yes the database has multiple linked tables; But, the focus is only on one called attendance.

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    It doesn't matter. You have included them all in your query, so the rules I mentioned apply. If you do not structure your query properly, you will not get the results you want.

    If you only really need the Attendence table, then use code like this, then get rid of all the other tables in your query and just use that one. Or at least start from there, and work your way up (adding one table at a time after you confirm you are getting what you expect).

    Also note that if you have any NULL values in the two fields you are adding together, you will need to use the NZ function to convert any NULLS to zero (you cannot include a NULL value in addition).

  7. #7
    George is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    295
    Thanks. The Nz function did it.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 06-28-2012, 10:10 PM
  2. A summing query?
    By russweb in forum Queries
    Replies: 8
    Last Post: 03-26-2012, 06:57 PM
  3. Summing problems
    By Katya in forum Queries
    Replies: 8
    Last Post: 11-26-2011, 08:43 PM
  4. summing
    By nashr1928 in forum Forms
    Replies: 18
    Last Post: 04-05-2011, 05:01 PM
  5. Issue summing two field values
    By w2vijay in forum Reports
    Replies: 4
    Last Post: 02-10-2010, 01:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums