Results 1 to 9 of 9
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Query difficulties

    I have the below query that is not returning the results desired. What I want is to return all stores that are in PUBLIC_ADC_GLP_LEDGER, but not in tblWeeklySales (for the specific POST_DATE). My below query returns/appends nothing. Thanks in advance for your help!



    Code:
    INSERT INTO tblWeeklySales ( STORENUM, POST_DATE, VALUE016, VALUE017, VALUE018, VALUE019, WeeklySales )
    SELECT PUBLIC_ADC_GLP_LEDGER_TAB.STORENUM, PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE, Sum(PUBLIC_ADC_GLP_LEDGER_TAB.VALUE016) AS VALUE016, Sum(PUBLIC_ADC_GLP_LEDGER_TAB.VALUE017) AS VALUE017, Sum(PUBLIC_ADC_GLP_LEDGER_TAB.VALUE018) AS VALUE018, Sum(PUBLIC_ADC_GLP_LEDGER_TAB.VALUE019) AS VALUE019, ([Value016]+[Value017])-([Value018]+[Value019]) AS WeeklySales
    FROM PUBLIC_ADC_GLP_LEDGER_TAB LEFT JOIN tblWeeklySales ON (PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE = tblWeeklySales.POST_DATE) AND (PUBLIC_ADC_GLP_LEDGER_TAB.STORENUM = tblWeeklySales.STORENUM)
    WHERE (((PUBLIC_ADC_GLP_LEDGER_TAB.DIVISION)=1) AND ((PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE) Is Null And (PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE)>#12/31/2010#) AND ((tblWeeklySales.STORENUM) Is Null))
    GROUP BY PUBLIC_ADC_GLP_LEDGER_TAB.STORENUM, PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE
    ORDER BY PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE;

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    Off the top of my head:

    PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE Is Null And
    PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE>#12/31/2010#

    A field can not be both Null and greater than a given date.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Very true...I'll have to play around with it more. That may not be the right syntax/logic, but that is what I'm trying to do...

  4. #4
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    I think it should be tblWeeklySales.POST_DATE is NULL...not PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE.

  5. #5
    Bwilliamson is offline Novice
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    Greenville, SC
    Posts
    8
    Change this:
    ((PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE) Is Null And (PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE)>#12/31/2010#)

    To this:
    ((PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE) Is Null OR (PUBLIC_ADC_GLP_LEDGER_TAB.POST_DATE)>#12/31/2010#)

    That will satisfy the logic.

  6. #6
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    I'll give the "OR" a shot. However, I'm trying to do an unmatched query. I want to append any record that is not in tblWeeklySales, but is in my PUBLIC table. The two fields I was trying to test for are the store number and date. Maybe I am going about this entirely wrong?

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    As someone mentioned, if you want to find records not in tblWeeklySales, that's the table that should be referred to.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    ok, I'll take another crack at it. Thanks for all the input.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,529
    I should have clarified, that referred to the "Is Null" test. It was kennejd in post 4 that first pointed it out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Expression Difficulties
    By Lea in forum Access
    Replies: 8
    Last Post: 01-18-2011, 04:42 AM

Tags for this Thread

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