Results 1 to 10 of 10
  1. #1
    sf827 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    16

    Referencing values within queries

    This is probably an easy one, but for the life of me I can't understand why this isn't working.



    Whenever I go run the following SQL expression I get a message asking for a value for "T1.N".

    SELECT T1.State, Count(T1.Outlet), T1.N
    FROM (SELECT State, Outlet, Count(Outlet) AS N FROM ExtractEvents AS T1 WHERE EventCode = "IN" OR "RETURNED" GROUP BY State, Outlet)
    GROUP BY T1.State

    Why is the reference not working?

    Thanks

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Access probably doesn't like your column name. Put it in square brackets - T1.[N]

  3. #3
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    It is a valid column, right? I see you are also using the letter N as an alias for your count. I would change that so that you can see where there are different values. "N" isn't a good name for a column or for an alias, it isn't very descriptive.

  4. #4
    sf827 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    16
    Hi aytee,

    I have run the subquery and it works fine, showing correct values under N It's just when I go to reference N that it won't work for me... Is there a way of referencing the "N" expression without using an alias?

    Thx

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I don't think I can help you further. That's all I would try, and if neither the square brackets or changing the name works, then I don't know what the problem is. Sorry.

  6. #6
    sf827 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    16
    Thanks anyway

  7. #7
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Finally figured it out - I wonder if you have too!

    The last part needs to be GROUP BY State, N

    It doesn't know what to do with the N, that is why it keeps asking for a value. Here's how I did it - I made two actual queries, instead of doing it all in one, then it became obvious!

  8. #8
    sf827 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    16
    Unfortunately not! Would you please post an example of the codes you used?

  9. #9
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Add ", N" to the end of your string

  10. #10
    sf827 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Dec 2011
    Posts
    16
    All good I've figured it out. Thanks

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

Similar Threads

  1. Displaying Zero Values from Queries
    By seageath in forum Queries
    Replies: 2
    Last Post: 12-13-2011, 02:39 AM
  2. Merge 2 queries with null? values
    By PrintShopSup in forum Queries
    Replies: 2
    Last Post: 10-03-2011, 09:09 PM
  3. Replies: 0
    Last Post: 02-27-2011, 04:21 PM
  4. Check Box Values in Queries
    By Rubz in forum Queries
    Replies: 3
    Last Post: 04-16-2010, 11:26 AM
  5. Return all values from two queries
    By matteu1 in forum Queries
    Replies: 0
    Last Post: 08-18-2009, 01:02 PM

Tags for this Thread

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