Results 1 to 4 of 4
  1. #1
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    143

    IIF function- compare 2 fields?

    I have 2 fields of state like sp_state and org_state. If sp_state is null I need to substitute the value of org_state for the state.



    What's wrong in my query?

    select sp_state, org_state, iif(sp_state= null, org_state, sp_state) as state from temp; some times both fields will be null, in that case I need to show sp_state value.



    Thanks in advance

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Cannot compare anything to Null. Null is an unknown so the result is unknown. Options:

    IIf(sp_state Is Null, org_state, sp_state)

    Nz(sp_state, org_state)


    Review:

    http://allenbrowne.com/casu-12.html

    http://allenbrowne.com/QueryPerfIssue.html
    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
    stalk is offline Competent Performer
    Windows 8 Access 2003
    Join Date
    May 2014
    Posts
    143
    Thank you June 7. None of these worked but they led me to understand the data. I imported this data from third party tool and the blank were imported with "NULL". Instead of using is null changed the query to= "NULL" an it worked

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Yep, "NULL" is simply text.

    Is this a one-time import? I would probably change all the text "NULL" to a real Null.
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 12-27-2013, 05:20 PM
  2. Results from local function won't compare
    By joethall in forum Queries
    Replies: 1
    Last Post: 07-27-2013, 08:13 AM
  3. Compare two fields
    By funkygoorilla in forum Programming
    Replies: 2
    Last Post: 01-18-2012, 09:43 PM
  4. SELECT WHERE compare two fields
    By bulb763 in forum Access
    Replies: 5
    Last Post: 03-22-2011, 09:56 AM
  5. Compare two fields!
    By finditsol in forum Forms
    Replies: 1
    Last Post: 02-11-2010, 01:43 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