Results 1 to 9 of 9
  1. #1
    Lorlai is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    107

    Simple Query for multiple ands


    I am trying to create a query that will only append product data if the product number does not currently exist in the master sheet, and only if that non-existing product number also has a product status of some form of "active" or "planning". I'm hitting a roadblock with access and can't make my query work. Currently my query is:


    Code:
    INSERT INTO [Products] ( [Product Number], [Product Name], [Product Color], [Product Status], [Product Start], [Product Finish], [Company Status], [Product Price] )
    SELECT [Master Data].[Product Number], [Master Data].[Product Name], [Master Data].[Product Color], [Master Data].[Product Status], [Master Data].[Product Start], [Master Data].[Product Finish], [Master Data].[Company Status], [Master Data].[Product Price]
    FROM [Products] RIGHT JOIN [Master Data] ON [Products].[Product Number] = [Master Data].[Product Number]
    WHERE ((([Products].[Product Number]) Is Null));
    I've tried adding the criteria for product status, but cannot get any results:

    Code:
    WHERE ((([Master Data].[Product Status]) Like "*Active*") AND (([Products].[Product Number]) Is Null));
    I figure it must be an easy solution to pull only Product Numbers that are null and have a status of "*Active*" or "*Planning*", but I can't find anything online and can't figure out what I'm doing wrong. Any advice would be greatly appreciated!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Don't understand. Which is the 'master sheet'.
    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.

  3. #3
    Lorlai is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    107
    Sorry, was working back and forth from Access to Excel! I mean the Master Data table, not master sheet.

  4. #4
    jwill is offline Advanced Beginner
    Windows Vista Access 2010 64bit
    Join Date
    Mar 2012
    Location
    MD
    Posts
    67
    Hey Lorlai,

    Your statement is working for me. Are you sure you have records to match your criteria?

  5. #5
    Lorlai is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    107
    Here is some dummy data, maybe I'm doing something incorrectly with my logic:

    Master Data Table
    Product name
    Product Color
    Product Status
    Product Start
    Product Finish
    Company Status
    Product Price
    12345 truck red active now later good lots
    45678 car black in planning now later good lots
    20245 bottle red active later now later good lots
    9991 pc silver complete before now good lots
    6692 phone grey complete before now good lots

    Product Table

    Product Number Product name Product Color product status product start product finish company status product price
    45678 car black in planning now later good lots
    9991 pc silver complete before now good lots
    6692 phone grey complete before now good lots
    564564 frog green complete before now good lots
    231247 dog brown complete before now good lots


    Based on these two tables, I want my query to find Products 12345 and 20245, which both are "*active*" and are not currently in Products, and append them into the product table. My current query doesn't find anything, even though i know there are these two products. Is something wrong with my logic perhaps?

    Thanks for you help!

  6. #6
    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
    [Products].[Product Number] = [Master Data].[Product Number]

    Your Master Data Table does not have a Product Number field according to your sample layout, but that might just be editing.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I created tables from the sample data and ran your query (copy/paste, no changes) and it worked. Those two records were added to the Products table.

    INSERT INTO Products ( [Product Number], [Product Name], [Product Color], [Product Status], [Product Start], [Product Finish], [Company Status], [Product Price] )
    SELECT [Master Data].[Product Number], [Master Data].[Product Name], [Master Data].[Product Color], [Master Data].[Product Status], [Master Data].[Product Start], [Master Data].[Product Finish], [Master Data].[Company Status], [Master Data].[Product Price]
    FROM Products RIGHT JOIN [Master Data] ON Products.[Product Number] = [Master Data].[Product Number]
    WHERE ((([Master Data].[Product Status]) Like "*Active*") AND ((Products.[Product Number]) Is Null));

    Do you want to provide your project for analysis? Follow instructions at bottom of my post.
    Last edited by June7; 05-10-2012 at 03:24 AM.
    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.

  8. #8
    Lorlai is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    107
    Something must be wrong with my computer. This was not working, and neither was an import process I had created. I go away for a day, and suddenly everything works! Thank you for all of your help!

  9. #9
    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

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

Similar Threads

  1. Simple Question about Multiple Table Queries
    By Access_Headaches in forum Access
    Replies: 4
    Last Post: 02-13-2012, 08:36 AM
  2. Replies: 1
    Last Post: 08-11-2011, 07:36 AM
  3. Simple Combo Box Multiple Select Question
    By ahamilton in forum Access
    Replies: 7
    Last Post: 03-17-2011, 01:38 PM
  4. need help with this simple query
    By dada in forum Programming
    Replies: 3
    Last Post: 08-20-2010, 07:08 AM
  5. simple query
    By taylorosso in forum Queries
    Replies: 1
    Last Post: 10-06-2009, 04:26 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