Results 1 to 2 of 2
  1. #1
    cazziewhelan is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2014
    Posts
    3

    If/Else Update Query

    Hi All,

    Hope someone can help, its been years since ive used SQL and now trying to remembered in college a few years ago!

    I am building a database to measure performance in business, based on targets and actual figures. There is a points system for those whos actual is equal or above there target figure. I want to build an update query, that will run and calculate points once actual figures are added to the database. I have managed ot write 2 seperate queries, one to update with points when hey exceed target and one to award no points if the exceed below the taret, but how can I combine these 2 queries as one, with an if else structure?

    To update when they exceed target


    Here are there queries I have working so far:

    UPDATE Result_Details SET Result_Details.Result_Value = "60"
    WHERE (((Result_Details.Actual_Value)>=[Target_Value]) AND ((Result_Details.KPI_Name)="Productivity"));


    UPDATE Result_Details SET Result_Details.Result_Value = "0"
    WHERE (((Result_Details.Actual_Value)<=[Target_Value]));


    Also, I have stored the point values in another table, and called them KPI_Pass and KPI_Fail, and tried to pass these paramaters into this query instead of the 60 value, but I was getting syntax error!

    Hope someone out there can help!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    You are setting your values to strings "60", not number 60 (no quotes).

    Wouldn't this AND ((Result_Details.KPI_Name)="Productivity") apply to both queries you currently have?

    Air code untested and assuming numeric values and you are always dealing with KPI_Name ="Productivity"

    Code:
    UPDATE Result_Details 
    SET Result_Details.Result_Value = IIf (Result_Details.Actual_Value)>=[Target_Value], 60,0)
    WHERE  ((Result_Details.KPI_Name)="Productivity")
     
    As I said Untested.

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

Similar Threads

  1. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  2. Replies: 1
    Last Post: 05-17-2013, 12:53 PM
  3. Replies: 2
    Last Post: 08-30-2012, 07:59 AM
  4. Replies: 4
    Last Post: 11-10-2011, 03:41 PM
  5. Replies: 1
    Last Post: 08-19-2011, 12:16 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