Results 1 to 7 of 7
  1. #1
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108

    Query Producing Blank Rows? Fault IIf Logic?


    The query below looks at two existing tables, and based on the "Geography" column in each, it adds a "ReportType" column that tells you whether you're looking at National or Local data. The first part of the query works fine, but the second part is producing hundreds of blanks rows with "Local" in the ReportType column. I can't figure out why, because nat_tv.Geography only has "National"...there shouldn't be any "Local" data in it. Any ideas? I'm wondering if my IIf logic is faulty...

    Code:
    SELECT IIf(loc_tv.Geography="National","National","Local") AS ReportType, loc_tv.Geography, loc_tv.Indication, loc_tv.[Variable Name], loc_tv.[Variable Value]
    FROM Localization_NatTV AS loc_tv
    UNION ALL SELECT IIf(nat_tv.Geography="National","National","Local") AS ReportType, nat_tv.Geography, nat_tv.Indication, nat_tv.[Variable Name], nat_tv.[Variable Value]
    FROM data_TVNational AS nat_tv;

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Syntax looks correct.

    Try doing a quick test: use "UNION" instead of "UNION ALL"


    Edit:

    The SQL UNION query is a SQL query to combine the result sets of 2 or more SQL SELECT statements. It removes duplicate rows between the various SELECT statements.
    The SQL UNION ALL query does not remove duplicates.

    See:
    http://www.techonthenet.com/sql/union.php
    http://www.techonthenet.com/sql/union_all.php
    Last edited by ssanfu; 12-18-2013 at 05:19 PM. Reason: Added references

  3. #3
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108
    Thanks, but unfortunately, I get the blank "Local" rows even when I run the second part of the query alone (i.e. without the UNION to the first query)...

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I get the blank "Local" rows even when I run the second part of the query alone (i.e. without the UNION to the first query)...
    So you have a lot of records in the table "data_TVNational" that are NULL? (data_TVNational.Geography is NULL??)
    How many records?

    How many records are returned using:
    Code:
    SELECT IIf(nat_tv.Geography="National","National","Local") AS ReportType, nat_tv.Geography, nat_tv.Indication, nat_tv.[Variable Name], nat_tv.[Variable Value]
    FROM data_TVNational AS nat_tv
    WHERE nat_tv.Geography IS NOT NULL;

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Want to provide sample data? Follow instructions at bottom of my post.
    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
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108
    Thanks, that works. I'm still stumped as to where the null value is, but this will be a great fix for the time being.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Whew, finally!!

    I'm still stumped as to where the null value is
    As a test, you could try:
    Code:
    SELECT * FROM data_TVNational WHERE data_TVNational.Geography IS NULL
    just to see what records are returned.

    Good luck with your project.

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

Similar Threads

  1. How to remove blank rows when I import from excel
    By timpepu in forum Import/Export Data
    Replies: 3
    Last Post: 09-14-2015, 04:04 PM
  2. Replies: 2
    Last Post: 12-12-2013, 02:13 PM
  3. Replies: 4
    Last Post: 01-24-2013, 12:11 AM
  4. Hiding rows when blank in a report.
    By ser01 in forum Reports
    Replies: 0
    Last Post: 02-27-2010, 10:29 PM
  5. msaccess fault error
    By msmoore in forum Access
    Replies: 4
    Last Post: 02-09-2010, 03:31 AM

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