Results 1 to 7 of 7
  1. #1
    gtsolid is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    19

    Post Condition under different tables

    Good morning,
    I'd like to use the same condition about quantity I use to discrimate di first table also in the second (instead of NOT EXISTS).

    For example with a fixed quantity, i don't need the double discrimination:
    Code:
    SELECT m.Codice, m.QntFROM Magazzino AS m
    WHERE m.[Prossimo_arrivo] Is Null AND
          ( (m.Qnt < 35 AND m.[Fascia_I] = True) OR
            (m.Qnt < 15 AND m.[Fascia_II] = True)
          ) AND
          NOT EXISTS (SELECT 1
                      FROM Magazzino_Grezzi as mg
                      WHERE mg.Codice = m.Codice
                     );
    How can I modify my current string?
    this is not working:
    Code:
    SELECT m.Codice, m.QntFROM Magazzino AS m
    WHERE m.[Prossimo_arrivo] Is Null AND
          ( (m.Qnt < 35 AND m.[Fascia_I] = True) OR
            (m.Qnt < 15 AND m.[Fascia_II] = True)
          ) AND
          (SELECT 1
                      FROM Magazzino_Grezzi as mg
                      WHERE mg.Codice = m.Codice AND
                      (mg.Qnt < 10)
                     );


  2. #2
    Join Date
    Apr 2017
    Posts
    1,681
    The outcome is determined by WHERE condition you use (either "Is Null" or "Is Not Null")!
    Code:
    SELECT m.Codice, m.Qnt
    FROM Magazzino m
    LEFT JOIN Magazzino_Grezzi mg ON mg.Codice = m.Codice
    WHERE mg.Codice Is Null/Is Not Null

  3. #3
    gtsolid is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    19
    Code:
    SELECT m.Codice, m.QntFROM Magazzino AS m
    LEFT JOIN Magazzino_Grezzi mg ON mg.Codice = m.Codice
    WHERE m.[Prossimo_arrivo] Is Null AND
          ( (m.Qnt < 35 AND m.[Fascia_I] = True) OR
            (m.Qnt < 15 AND m.[Fascia_II] = True)
          ) AND
            mg.Qnt < 10;
    Some codes are not displayed, but I don't understand the reason.
    Maybe I have to add something like THIS?
    Code:
    AND
    		mg.Qnt < 10 OR NOT EXISTS;

  4. #4
    Join Date
    Apr 2017
    Posts
    1,681
    You can use expression like Nz(mg.Qnt,0) < 10, to have empty fields included.

  5. #5
    gtsolid is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    19
    It works. But why my solution don't? How does NZ works?

  6. #6
    Join Date
    Apr 2017
    Posts
    1,681
    Quote Originally Posted by gtsolid View Post
    It works. But why my solution don't? How does NZ works?
    In case the field value is null, it is replaced in expression with value of 2nd parameter (in your case with 0)

    NB! The 2nd parameter can be of any valid data type. E.g. you have a table of items with ItemID and Name, and sometimes the name field may be empty. In queries, you can display some text for such entries, like
    Code:
    SELECT ItemID, ItemCode, Nz(ItemName,"The Name is missing!") As ItemName FROM tblItems
    About your solution not working: Records, where you are trying to do some mathematical/logical operations with Null (Empty) values, are left out from query result dataset

  7. #7
    gtsolid is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    19
    thanks, it works fine.

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

Similar Threads

  1. Where condition
    By DavidTCH in forum Access
    Replies: 3
    Last Post: 03-25-2016, 09:07 PM
  2. Replies: 6
    Last Post: 05-09-2013, 08:03 PM
  3. Replies: 1
    Last Post: 04-05-2013, 12:49 PM
  4. Help with using the AND condition
    By ssturges in forum Access
    Replies: 1
    Last Post: 11-25-2012, 12:36 AM
  5. Replies: 2
    Last Post: 07-07-2011, 08:25 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