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

    Show result whether in two tables or not

    Morning,

    I have two tables (Table1 'MBXStats' & Table2 'DisconnectedMBXs'). In order to establish whether a mailbox is disconnected, the two tables are compared and if the 'displayname' appears in both tables it's disconnected. However, I want to be able to see all mailboxes (disconnected or not) with a statement that advises its status...

    I.e. I wrote a SQL statement (below) which works fine if I 'show the table' in design view; but it only shows those mailboxes in the DisconnectedMBXs table. If I remove the table in design view, then all entries appear duplicated (only 1 user shows).

    Code:
     IIf(Not IsNull([DisconnectedMBXs].[disconnectdate]),1,0)


  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 get the results you want with a Query and an outer join. No IIF needed.

  3. #3
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108
    Not sure how a Outer Join would work? Surely if I try and do any type of join it will only provide the information that is in both tables...

  4. #4
    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,726
    For records in MBXStats and Not In DisconnectedMBXs
    Code:
    Select  mailboxId from MBXStats 
    where mailboxId Not In
     (Select mailboxId From DisconnectedMBXs)
    For records in both tables

    Code:
    Select  mailboxId from MBXStats 
    where mailboxId  In
     (Select mailboxId From DisconnectedMBXs)
    You will have to use your own field names for mailboxId -- whatever you called in each of the tables.

  5. #5
    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
    Quote Originally Posted by dr4ke View Post
    Not sure how a Outer Join would work? Surely if I try and do any type of join it will only provide the information that is in both tables...
    Outer Joins will show *all* the records in one table and only records in the other where the join field matches.

  6. #6
    dr4ke is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    108
    Thanks, I managed to get what I want:

    First I brought both tables together

    Code:
     SELECT *FROM allmailboxstats LEFT JOIN disconnectedmailboxes ON allmailboxstats.displayname=disconnectedmailboxes.displayname;
    Then I did the working out:

    Code:
     SELECT FullQueryTest.allmailboxstats.ID, FullQueryTest.allmailboxstats.DisplayName, FullQueryTest.OU, OULookup.[Business Unit], FullQueryTest.maxsendsize, FullQueryTest.prohibitsendreceivequota, FullQueryTest.HiddenFromAddressListsEnabled, FullQueryTest.IsValid, FullQueryTest.DisconnectDate, FullQueryTest.DisconnectReason, IIf(IsNull(DisconnectDate) And ((maxsendsize)<>"0 B (0 bytes)") And ((HiddenFromAddressListsEnabled)=No),1,0) AS Active, IIf(IsNull(DisconnectDate) And ((maxsendsize)="0 B (0 bytes)"),1,0) AS Disabled, IIf(IsNull(DisconnectDate) And ((allmailboxstats.HiddenFromAddressListsEnabled)=Yes) And ((allmailboxstats.maxsendsize)<>"0 B (0 bytes)"),1,0) AS Suspended, IIf(Not IsNull(DisconnectDate) And (((DisconnectDate)>=Now()-210) AND ((IsValid)=Yes)),1,0) AS Deleted
    FROM (FullQueryTest INNER JOIN MailboxSizes ON FullQueryTest.prohibitsendreceivequota=MailboxSizes.Mailboxes) INNER JOIN OULookup ON FullQueryTest.OU=OULookup.OU;
    The only problem is that there are duplicates, but I assume that's because the displayname is duplicated in the second table so therefore shows up twice in the query?

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

Similar Threads

  1. Query not show result
    By Arsalan in forum Database Design
    Replies: 2
    Last Post: 01-13-2013, 02:57 PM
  2. show a query result in a text box
    By mikael in forum Access
    Replies: 2
    Last Post: 09-13-2012, 02:17 AM
  3. Replies: 2
    Last Post: 05-30-2012, 07:53 AM
  4. Replies: 1
    Last Post: 09-28-2011, 09:48 PM
  5. Replies: 1
    Last Post: 07-12-2009, 05:09 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