Results 1 to 8 of 8
  1. #1
    DB2010MN26 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    37

    Best query type for returning value based on a scale

    I'm trying to determine if its possible to do the following in a single update query. I have two fields, [PEG] and [PEGSCORE]. [PEGSCORE] is the field that will be updated as a result of my query, [PEG] is the field that is used to determine the value entered in [PEGSCORE]. What I want to do is the following:

    If PEG<.5, update [PEGSCORE] to 3


    If PEG<1, update [PEGSCORE] to 2
    If PEG<2, update [PEGSCORE] to 1
    all other values return value 0

    Is it possible to do this in a single update query or will I have to run 4 seperate ones for each potential outcome?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You should be able to do it with an IIF statement or a UDF.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Saving calculated/dependent data can be bad idea. If PEG value were changed, the PEGSCORE could then be incorrect. This PEGSCORE can be calculated whenever needed.
    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
    DB2010MN26 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    37
    Understood, but to clarify, I'm appending the source data to a new table prior to performing these calculations.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Appending source data to a new table - now I am really confused. Why duplicating records? Doesn't alter my comment about dependent calcs.
    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.

  6. #6
    DB2010MN26 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    37
    I'm feeding this information into a table in access from an excel file, I'm not pulling the data from an ODBC table or anything, so if PEG changes, I'll be recalcuating/appending the information into the database regardless.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Okay, if you must, have you figured out the IIf?

    In the UpdateTo row under PEGSCORE:

    IIf(PEG<.5,3, IIf(PEG<1,2, IIf(PEG<2,1,0)))
    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.

  8. #8
    DB2010MN26 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    37
    Quote Originally Posted by June7 View Post
    Okay, if you must, have you figured out the IIf?

    In the UpdateTo row under PEGSCORE:

    IIf(PEG<.5,3, IIf(PEG<1,2, IIf(PEG<2,1,0)))
    That works perfect, thanks!

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

Similar Threads

  1. Replies: 1
    Last Post: 11-16-2011, 11:56 PM
  2. Replies: 0
    Last Post: 04-18-2011, 01:01 PM
  3. Query - Returning ID instead of Value...??
    By Poolio in forum Queries
    Replies: 5
    Last Post: 04-18-2011, 07:10 AM
  4. Replies: 0
    Last Post: 05-14-2010, 07:28 AM
  5. Replies: 0
    Last Post: 02-15-2009, 09:14 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