Results 1 to 5 of 5
  1. #1
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193

    Question Query to show records based on input field if another field is blank or has a value.

    Hello Brains trust.

    I've been struggling with this query that is used to generate a report. I think I need to use the IIF statement to get my desired result, but am unsure how.

    Code:
    SELECT SoftwareKeys.OrderNo, SoftwareKeys.PurchaseDate, SoftwareKeys.SoftwareName, SoftwareKeys.KeyNo, SoftwareKeyCodes.SoftwareLevel, SoftwareKeyCodes.SoftwareLevelCode, SoftwareKeyCodes.Comment, SoftwareKeys.CustomerID
    FROM Customers INNER JOIN (SoftwareKeys INNER JOIN SoftwareKeyCodes ON SoftwareKeys.KeyNo = SoftwareKeyCodes.KeyNo) ON Customers.CustomerID = SoftwareKeys.CustomerID
    WHERE (((SoftwareKeys.OrderNo) Like "*" & [Enter the purchase order number:] & "*"));
    As it is now, the query returns only those records where the SoftwareKeys.OrderNo has an entry in the SoftwareKeys.CustomerID field. (i.e not Null)

    What I need the query to do is show ALL the records for SoftwareKeys.OrderNo, regardless of whether SoftwareKeys.CustomerID is Null of not.

    Thanks in advance for your time and input.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Have you tried:
    Code:
    SELECT SoftwareKeys.OrderNo, SoftwareKeys.PurchaseDate, SoftwareKeys.SoftwareName, SoftwareKeys.KeyNo, SoftwareKeyCodes.SoftwareLevel, SoftwareKeyCodes.SoftwareLevelCode, SoftwareKeyCodes.Comment, SoftwareKeys.CustomerIDFROM Customers INNER JOIN (SoftwareKeys INNER JOIN SoftwareKeyCodes ON SoftwareKeys.KeyNo = SoftwareKeyCodes.KeyNo) ON Customers.CustomerID = SoftwareKeys.CustomerID ;
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    You will need to change one or both of your joins, methinks. An INNER join can only return records where both fields are equal, and nothing equals Null. You want ALL the records from one table, and from the other table, whatever records match between the joined fields. Double click on the joins and read the explanations for the 3 options.

    What I don't get is how you can have a software key value in an orders table but no related customer id.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193
    Hi Micron and Bob.

    Quote Originally Posted by Micron View Post
    You will need to change one or both of your joins, methinks. An INNER join can only return records where both fields are equal, and nothing equals Null. You want ALL the records from one table, and from the other table, whatever records match between the joined fields. Double click on the joins and read the explanations for the 3 options.

    What I don't get is how you can have a software key value in an orders table but no related customer id.


    Thank you very much for your replies. I have solved the issue using your suggestions.

    Please see new code below;

    Code:
    SELECT SoftwareKeys.OrderNo, SoftwareKeys.PurchaseDate, SoftwareKeys.SoftwareName, SoftwareKeys.KeyNo, SoftwareKeyCodes.SoftwareLevel, SoftwareKeyCodes.SoftwareLevelCode, SoftwareKeyCodes.Comment, SoftwareKeys.CustomerID, Customers.CompanyName
    FROM (Customers RIGHT JOIN SoftwareKeys ON Customers.CustomerID = SoftwareKeys.CustomerID) INNER JOIN SoftwareKeyCodes ON SoftwareKeys.KeyNo = SoftwareKeyCodes.KeyNo
    WHERE (((SoftwareKeys.OrderNo) Like "*" & [Enter the purchase order number:] & "*"));
    Micorn, Bad practice I know, but there is no Orders table. The OrderNo is stored with KeyNo record.

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Micorn, Bad practice I know, but there is no Orders table
    Well I suppose we will be 'seeing' you later!
    Regards,
    Micron
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 1
    Last Post: 12-28-2016, 11:39 AM
  2. Replies: 5
    Last Post: 03-03-2015, 09:08 PM
  3. populating field in form based on input field
    By BrandonFinn in forum Forms
    Replies: 7
    Last Post: 10-30-2014, 10:45 AM
  4. Query wont show records with a blank field
    By bignate in forum Queries
    Replies: 2
    Last Post: 09-03-2013, 04:45 AM
  5. Replies: 5
    Last Post: 05-22-2013, 12:38 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