Results 1 to 3 of 3
  1. #1
    shifty is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    5

    [MS SQL] UNION ALL Help

    Design a Union All query to compute salary bonuses using the following guide


    Teacher class >= 20 AND >= 90% Enrollment = $100 Bonus
    Teacher class >= 20 AND < 90% Enrollment = $50 Bonus
    Teacher class < 20 AND >= 90% Enrollment = $25 Bonus
    Teacher class < 20 AND < 90% Enrollment = $1 Bonus
    I wanted to use an IIF but my Prof hopes make an "efficient" UNION ALL.

    It's all in one table with variables: Class.Teacher, Class.Enrollment, Class.Capacity

    Can anyone point me out where to start? I made a working IFF table but I can't figure out how to make the bonuses work without 4 union all's... This is what I have so far but the IIF isn't working in this form.


    SELECT Class.Teacher,
    SUM(((Class.Enrollment / Class.Capacity >= 0.90) AND IFF(Class.Enrollment >=20, "$100.00", "$25.00")))) AS TB
    FROM Class
    GROUP BY Class.Teacher


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,969
    Really don't know why a UNION ALL is needed.

    Don't put numbers within quote marks.

    SELECT Class.*, Enrollment/Capacity AS PctEnroll, IIf(PctEnroll >= 0.90, IIf(Enrollment >= 20, 100, 25), IIf(Enrollment >= 20, 50, 1)) AS Bonus FROM Class;


    Sum() is an aggregate function and is used to calc summary data of records in a TOTALS (GROUP BY) query - in other words, add up all the data in a field or expression for ALL records. If that's what you want:

    SELECT Sum(IIf(Enrollment/Capacity >= 0.90, IIf(Enrollment >= 20, 100, 25), IIf(Enrollment >= 20, 50, 1))) AS SumBonus FROM Class;

    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.

  3. #3
    shifty is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    5
    That query works beautifully. Ill just ignore the Union then Thank you!

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

Similar Threads

  1. Union Query
    By scoe in forum Queries
    Replies: 8
    Last Post: 08-06-2013, 06:02 PM
  2. Union Query Help
    By pmp in forum Queries
    Replies: 4
    Last Post: 10-28-2011, 06:41 AM
  3. Union & union all
    By jasonbarnes in forum Queries
    Replies: 4
    Last Post: 10-27-2011, 12:30 PM
  4. Union or better way.
    By kevin28 in forum Access
    Replies: 2
    Last Post: 09-06-2011, 02:42 PM
  5. Union Query
    By jlclark4 in forum Queries
    Replies: 3
    Last Post: 02-25-2011, 08:21 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