Results 1 to 13 of 13
  1. #1
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126

    Adding row ID to an expression

    I have a query with a list of games won and lost. I am trying to sum the wins and losses to show the total of games played.

    Using the expression
    Code:
    GmsPlayed: Sum([W16]+[L16])
    I get a message about needing the ID but I have not had any success in doing so.

    The query is called 'NFLStandingsQry' and the team ID would be 'NFLID' all data is from the source table 'NFLTeamsT'.

    I am not sure how to properly include the ID in the formula.

    Thanks
    Jim O
    Last edited by JimO; 09-12-2016 at 03:42 PM.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    How about showing the SQL of the query you are trying to run?

  3. #3
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    Code:
    GmsPlayed: Sum([W16]+[L16])
    I have tried
    Code:
    GmsPlayed: Sum([NFLID].[W16]+[NFLID].[L16])
    and some other like combinations with no success.

    Jim O

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    That is not SQL code, that is a calculated field you posted. To get that, just change your query to SQL View and copy and paste the code here.
    As Orange requested, if you post your whole query, it might shed all light on the situation.

    Also, note that SUM and + do the same thing. You only need one or the other, not both.
    I would recommend just sticking to:
    Code:
    GmsPlayed: [W16]+[L16]
    as the use of the SUM function is usually used in Aggregate Queries, which involves grouping records (and having a GROUP BY clause in your Query).

    Also, is NFLID the name of your table or a field?
    If it is the name of a field, then this is an invalid statement:
    Code:
    [NFLID].[W16]+[NFLID].[L16]
    as you can only preface field names with object names (like tables).

  5. #5
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    I think this is what you are requesting.

    SELECT NFLTeamsTbl.NFLID, NFLTeamsTbl.Region, NFLTeamsTbl.[Full Name], NFLTeamsTbl.Team, NFLTeamsTbl.W16, NFLTeamsTbl.L16, NFLTeamsTbl.Conference
    FROM NFLTeamsTbl
    ORDER BY NFLTeamsTbl.W16 DESC;

    Jim O

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    OK, so your query should look like:
    Code:
    SELECT NFLTeamsTbl.NFLID, NFLTeamsTbl.Region, NFLTeamsTbl.[Full Name], NFLTeamsTbl.Team, NFLTeamsTbl.W16, NFLTeamsTbl.L16, NFLTeamsTbl.Conference, [W16] + [L16] as GmsPlayed
    FROM NFLTeamsTbl
    ORDER BY NFLTeamsTbl.W16 DESC;

  7. #7
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    Thanks Joe,

    That seems to be working. I was not aware of this approach, thanks for the information.

    Jim O

  8. #8
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You can either use the Query Builder, or write the SQL code directly.

    You would have gotten pretty much the same SQL code as I posted if you went in to the Query Builder and added a Calculated Field like this:
    Code:
    GmsPlayed: [W16] + [L16]

  9. #9
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    I tried that and kept getting a prompt for an ID.

    Jim O

  10. #10
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I tried that and kept getting a prompt for an ID.
    But you were also using the SUM function, right?
    Did you actually try doing it without using SUM?

  11. #11
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    Yes, I tried it both ways.

    Jim O

  12. #12
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    IDK, that doesn't make much sense to me. I tried setting up your table on Access 2010, and used those exact steps and it worked for me.

    If you had to qualify it, you would do that with the table name, i.e.
    Code:
    [NFLTeamsTbl].[W16] + [NFLTeamsTbl].[L16] as GmsPlayed

  13. #13
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126
    Thank you very much for the help and tutorial. It is working fine now and if I run into an issue again I will be back on here asking for help.

    Thanks
    Jim O

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

Similar Threads

  1. Replies: 4
    Last Post: 05-03-2016, 01:51 PM
  2. Adding a 3rd condition in IIf(IsNull expression
    By Holli in forum Programming
    Replies: 2
    Last Post: 05-20-2015, 01:04 PM
  3. Replies: 2
    Last Post: 12-21-2013, 11:37 AM
  4. Replies: 1
    Last Post: 07-21-2013, 09:40 PM
  5. Replies: 3
    Last Post: 04-30-2013, 05:32 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