Results 1 to 7 of 7
  1. #1
    Worm is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    6

    Between function in query Expr


    Have a table with supplier name and sales to date. I would like to run a query that has a third col using an expr that puts either A B or c depending on the value

    Expr1: IIf([SumOfNet value]>100000,"A",IIf([SumOfNet value]=0,"B",IIf([SumOfNet value]<100000,"C","")))


    However I want to change the values to having a between range for each category

    A between 0 and 50000
    B between 50000 and 100000
    C between 100000 and 1000000

    But cant get the formula right.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    select 'A' as myFld from tbl where [SumOfNet value] between 0 and 50000
    union
    select 'B' as myFld from tbl where [SumOfNet value] between 50000 and 100000
    union
    select 'C' as myFld from tbl where [SumOfNet value] between 100000 and 1000000

  3. #3
    Worm is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    6
    Thanks for the quick reply.. however im not to sure where I would put that formula.....it took me ages to get my expr to work..

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    its not a formula, its the query.

  5. #5
    Worm is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    6
    Hi

    This is the query at the mo

    SELECT Query1_1.[Supplier No], Query1_1.[Supplier Name], Query1_1.[SumOfNet value], Query1_1.Category, IIf([SumOfNet value]>100000,"A",IIf([SumOfNet value]=0,"B",IIf([SumOfNet value]<100000,"C",""))) AS Expr1
    FROM Query1 AS Query1_1


    Which results in below. I cant seem to integrate your code into to replace mine..... Sorry for the lack of skill

    Supplier No Supplier Name SumOfNet value Category Expr1
    11048 BLACKWELL UK LTD 50,592.35
    C
    11064 CAPITA BUSINESS SERVICES LTD 182,844.60
    A

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    BETWEEN AND operator is not necessary for your requirement. Just makes for a very long expression.

    Choose() and Switch() can often be used instead of IIf().

    Switch([SumOfNet]<=50000, "A", [SumOfNet]<=100000, "B", [SumOfNet]<=1000000, "C")
    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.

  7. #7
    Worm is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    6
    Thanks both for the replies. Ive never come across the Switch function before and it worked great... saved me much headache and good for future

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

Similar Threads

  1. SQL Query turning field into an Expr
    By Huddle in forum Access
    Replies: 2
    Last Post: 08-15-2012, 02:02 PM
  2. Expr. to calculate 'Age' from Date field
    By JohnB47 in forum Queries
    Replies: 18
    Last Post: 08-17-2011, 04:10 AM
  3. Replies: 9
    Last Post: 01-21-2011, 03:57 PM
  4. Replies: 4
    Last Post: 11-19-2010, 07:21 PM
  5. Expr to Form and Table
    By OpsO in forum Access
    Replies: 3
    Last Post: 07-19-2010, 10:05 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