Results 1 to 6 of 6
  1. #1
    JHJapay is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2020
    Posts
    6

    How to group a number range in MS Access? Say >2 should always show as 1 in the query.

    I wanted to display in my query the value of "1" for results ranging from 0 to 1.99999 or >2;
    And then "2" for results ranging from 2 to 2.99999 or >3;
    And then "3" for results ranging from 3 to 3.99999 or >4, and so on and so forth.

    I am computing for salary increase for every 3 years that the employee served the company



    Please help.

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2016
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Assumptions:
    Field containing raw data is called Valuex
    Query field to return results is called Calc
    Table name is Table2

    SQL statement

    Code:
    SELECT Table2.id, Table2.Valuex, Int([ValueX]) AS Calc
    FROM Table2;
    Attached Thumbnails Attached Thumbnails Capture5.JPG  

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Don't quite understand "from 0 to 1.99999 or >2". Should that be <2?

    What results - a field in table?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2016
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Relooking at your ask, I noticed an error in my original SQL Statement.

    Revised:

    Code:
    SELECT Table2.id, Table2.Valuex, IIf([ValueX]<2,2,Int([ValueX])) AS Calc
    FROM Table2;

  5. #5
    CarlettoFed is offline Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    274
    Maybe it would be better like this:
    Code:
    SELECT Table2.id, Table2.Valuex, IIf([ValueX]<2,1,Int([ValueX])) AS Calc
    FROM Table2;

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    I suspect you already have an answer but you really need to clear about your requirement

    the value of "1" for results ranging from 0 to 1.99999 or >2; - so value of 4.1 would show 1 and a value of 4 would show 1
    And then "2" for results ranging from 2 to 2.99999 or >3; - so value of 4.1 would show 2 and a value of 4 would show 2
    And then "3" for results ranging from 3 to 3.99999 or >4, - so value of 4.1 would show 3 and a value of 4 would show? what?

    4.1 can only be converted one value and I suspect it would be 4, but that is not clear from your description of the requirement. For the future, always better to provide examples that cover the range of possible values and most importantly, the outcome you want from that example data



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

Similar Threads

  1. Replies: 9
    Last Post: 10-07-2014, 06:53 PM
  2. Replies: 17
    Last Post: 04-24-2014, 10:58 AM
  3. Report Group - Show empty Group
    By crimedog in forum Reports
    Replies: 2
    Last Post: 12-30-2013, 01:06 AM
  4. Replies: 8
    Last Post: 10-09-2013, 02:09 AM
  5. Replies: 2
    Last Post: 06-21-2012, 07:40 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