Access (2007) - Creating a query which changes wages depending upon age

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Edward Gorman
    New Member
    • Aug 2010
    • 2

    Access (2007) - Creating a query which changes wages depending upon age

    Hello Everyone,

    I'm having abit of difficulty with an aspect of Access. I wish to create a query which changes a persons wage depending upon their age. This is what I have done so far:
    Code:
    SELECT Tble_Staff.[Unique Staff Number], Tble_Staff.[Age], Tble_Staff.[Age] AS Normal_Wage
    FROM Tble_Staff
    WHERE IIF([Normal_Wage]=12,13,IIF([Normal_Wage]=13,13.34,IIF([Normal_Wage]=14,13.78,IIF([Normal_Wage]=15,14,IIF([Normal_Wage]=16,14.50,IIF([Normal_Wage]=17,14.70,IIF([Normal_Wage]>=18,15.60,"Invalid Number")))))));
    Now, I have the feeling that this doesn't work due to the fact that I utilise the [Normal_Wage] variable twice. However, I am unsure as to how to avoild this.
    Any help or suggestions would be greatly appreciated. I need to get this done ASAP.

    Thanks,

    Edward Gorman
  • liimra
    New Member
    • Aug 2010
    • 119

    #2
    Solution/

    I think you are creating circular error. Anyways Assuming you have table named "Tble_Staff " and two Fields "Unique Staff Number" and "Age". Here is the Code and it works,

    Code:
    SELECT Tble_Staff.[Unique Staff Number], Tble_Staff.Age, IIf([Age]=12,13,IIf([Age]=13,13.34,IIf([Age]=14,13.78,IIf([Age]=15,14,IIf([Age]=16,14.5,IIf([Age]=17,14.7,IIf([Age]>=18,15.6,"Invalid*Number"))))))) AS Normal_Wage
    FROM Tble_Staff;
    Regards,
    Ali

    Comment

    • liimra
      New Member
      • Aug 2010
      • 119

      #3
      Adjustment

      Dear Edward,

      The above mentioned statement won't resolve Null & Unspecified values but this will
      Code:
      SELECT Tble_Staff.[Unique Staff Number], Tble_Staff.Age, IIf(Age Is Null,"Invalid Number",IIf([Age]=12,13,IIf([Age]=13,13.42,IIf([Age]=14,13.78,IIf([Age]=15,14,IIf([Age]=16,14.5,IIf([Age]=17,14.7,IIf([Age]>=18,15.6,"Invalid Number")))))))) AS Normal_Wage
      FROM Tble_Staff;
      Regards,
      Ali

      Comment

      • Edward Gorman
        New Member
        • Aug 2010
        • 2

        #4
        Thank you very much liimra, I really do appreciate this.
        Regards,
        Edward

        Comment

        Working...