Results 1 to 9 of 9
  1. #1
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108

    Union Query to return Null

    Hi, I recently learnt of the UNION query but am now having some difficulty implementing it to do exactly what I want! Currently the below works, but only when I take 'Query 4' out of the equation - because Query 4 holds some '#Error' and '0' values (which is fine! It does so because of the calculations within the sheet which are trying to divide by 0 because of the data in the table - this may change hense why i'm still keeping the query).



    How can I make a Union query show me the fields whether they have values or not? I'm presuming it wont work because of the 'error' value...


    Code:
     SELECT 
    [SANName],[AggregateName], [DailyIncreaseGB], [TimeLeft], [UsedPercentage]
    FROM [Query1];
    UNION SELECT [SANName],[AggregateName], [DailyIncreaseGB], [TimeLeft], [UsedPercentage]
    FROM [Query2];
    UNION SELECT [SANName],[AggregateName], [DailyIncreaseGB], [TimeLeft], [UsedPercentage]
    FROM [Query3];
    UNION SELECT [SANName],[AggregateName], [DailyIncreaseGB], [TimeLeft], [UsedPercentage]
    FROM [Query4];

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Have you tried fixing the errors in your underlying queries?

    For example, let's say you have a division by zero error. You can change the formula so that it returns 0 instead of an error like this.
    Instead of having:
    Code:
    UsedPercentage: [Field1]/[Field2]
    try something like this:
    Code:
    UsedPercentage: IIF([Field2]=0,0,[Field1]/[Field2])+0

  3. #3
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108
    Thank you :-) I will try that very shortly!!

  4. #4
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108
    It doesn't seem to be working

    Code:
     IIF([DailyIncreaseGB]=0,0,(Int(Round(LFAS01Aggr0DateComparison.LastFreeGB)/(DailyIncreaseGB),1)))+0
    Daily Increase is what returns 0 in the query when dividing the used difference by the date difference.

    Then You divide the Free memory by the Daily Increase to get a Time Left.

    Any thoughts?

  5. #5
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108
    I seem to have it working

    Code:
     IIF([DailyincreaseGB]=0,0,(Int(Round((LFAS01Aggr0DateComparison.LastFreeGB)/(DailyIncreaseGB),1)))) AS TimeLeft
    but don't have the '+0' in it -- what does this do?

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    but don't have the '+0' in it -- what does this do?
    The NZ function, by default, returns a text value. So adding zero just coerces it to return a numeric value.

  7. #7
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108
    Sorry; the NZ Function??

    Where would I put the +0 in this code please?

    Code:
     IIF([DailyincreaseGB]=0,0,(Int(Round((LFAS01Aggr0DateComparison.LastFreeGB)/(DailyIncreaseGB),1)))) AS TimeLeft

  8. #8
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Wow, I must have "Monday morning brain" today!

    I was confusing this with another thread I was helping out on. Of course, you aren't using the NZ function, so you can ignore that statement.
    How you have written the formula in post #5 should work fine.

    Sorry for the confusion!

  9. #9
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108
    Aha well it's now Friday morning and you've just given me my first chuckle of the day! So thanks for that :-)

    Thanks for all your help! It's very much appreciated.

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

Similar Threads

  1. Count query return zero instead of null/blank
    By dhicks19 in forum Queries
    Replies: 1
    Last Post: 04-19-2012, 07:52 AM
  2. Query return 0 for null values
    By rachello89 in forum Access
    Replies: 4
    Last Post: 02-23-2012, 08:38 AM
  3. Return Null as Zero
    By bbshriver in forum Reports
    Replies: 12
    Last Post: 10-19-2010, 01:49 PM
  4. No return on Null values
    By forrestapi in forum Queries
    Replies: 4
    Last Post: 10-18-2010, 08:09 AM
  5. Return 0 instead of null
    By salisbut in forum Queries
    Replies: 1
    Last Post: 08-07-2010, 12:01 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