Results 1 to 6 of 6
  1. #1
    wcrimi is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2014
    Posts
    142

    Query with a Tabe with a Range of Values

    I have a table with 3 critical pieces of information.

    Class
    Grade
    Purse

    The Purse value can contain a large number of possible values.

    I will create a second table with Class, Grade a "Purse Range", and a PAR Value for that "Purse Range".

    For example in Table 1: Class, Grade, Purse

    STK.....1.....750k
    STK.....1.....500k
    STK.....1.....900k
    STK.....1.....250k
    STK.....2.....150k
    STK.....2.....200k
    STK.....3.....100K


    Table 2: Class, Grade, Purse Minimum, Purse Maximum, Par Value

    STK.....1.....600k.....999k.....110
    STK.....1.....500k.....599k.....109
    STK.....1.....400k.....499k.....108


    The first record in table 1 has a purse of 750k. That falls between 600k and 999k. I want the query to return 110.

    The second record in table 1 has a purse of 500k. That falls between 500k and 599k. I want the query to return 109.



    The third record in table 1 has a purse value of 900k. That falls between 600k and 999k. I want the query to return 110.

    etc....

    Thanks

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    The SQL Code of your Query would look something like this:
    Code:
    SELECT Table1.Class, Table1.Grade, Table1.Purse, Table2.[Par Value]
    FROM Table1 INNER JOIN Table2 ON (Table1.Grade = Table2.Grade) AND (Table1.Class = Table2.Class)
    WHERE (((Table1.Purse) Between [Table2].[Purse Minimum] And [Table2].[Purse Maximum]));

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I should also clarify, all your "Purse" fields will need to be numeric for this to work. If they are text fields, it will not work.

  4. #4
    wcrimi is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2014
    Posts
    142
    Thanks Joe. I'll give that a try this evening. Thanks so much for the help.

  5. #5
    wcrimi is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2014
    Posts
    142
    Quote Originally Posted by JoeM View Post
    The SQL Code of your Query would look something like this:
    Code:
    SELECT Table1.Class, Table1.Grade, Table1.Purse, Table2.[Par Value]
    FROM Table1 INNER JOIN Table2 ON (Table1.Grade = Table2.Grade) AND (Table1.Class = Table2.Class)
    WHERE (((Table1.Purse) Between [Table2].[Purse Minimum] And [Table2].[Purse Maximum]));

    I'm having a problem with this.

    As coded, I was getting some missing operator and syntax errors on the "Where" part of this. I played around with it and eventually got it to work perfectly. Unfortunately, I made some changes to other queries that fed this one and somehow it destroyed this query. I've tried to recreate it, but it won't work. I must have stumbled onto the right syntax for the statement initially because I've been unable to get it to work. I've spent a couple of hours on that single statement. HELP!

  6. #6
    wcrimi is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2014
    Posts
    142
    Found it. I made an extra copy of the syntax. Thanks

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

Similar Threads

  1. Replies: 6
    Last Post: 02-25-2014, 12:48 AM
  2. Replies: 1
    Last Post: 07-10-2013, 12:43 PM
  3. Maximum values from a date range
    By FatLane in forum Queries
    Replies: 3
    Last Post: 07-10-2012, 05:09 PM
  4. group by a range of values
    By therzakid in forum Queries
    Replies: 3
    Last Post: 07-24-2011, 02:22 PM
  5. Sum of Values over date range
    By bosnian in forum Queries
    Replies: 1
    Last Post: 01-12-2010, 03:41 PM

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