Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9018705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:35:50+00:00 2026-06-16T04:35:50+00:00

I have this SQL query in Access, which works fine: SELECT TableA.FieldA As [Code],

  • 0

I have this SQL query in Access, which works fine:

SELECT TableA.FieldA As [Code],
   Count(TableA.FieldC) AS [Count]
FROM ((MainTable)
   LEFT JOIN TableA ON MainTable.FieldB = TableA.FieldB)
WHERE (((MainTable.DateOf)>=#1/1/2012#))
   AND Clng(TableA.FieldA) >= 119593451
   AND Clng(TableA.FieldA) <= 119593461
GROUP BY TableA.FieldA;

But when I try another left join, like so:

SELECT TableA.FieldA As [Code],
   Count(TableA.FieldC) AS [Count]
FROM ((MainTable)
   LEFT JOIN TableA ON MainTable.FieldB = TableA.FieldB)
   LEFT JOIN TableB ON TableA.FieldD = TableB.FieldD
WHERE (((MainTable.DateOf)>=#1/1/2012#))
   AND Clng(TableA.FieldA) >= 119593451
   AND Clng(TableA.FieldA) <= 119593461
GROUP BY TableA.FieldA;

I am using the parenthesis in the FROM claused based on this: http://nm1m.blogspot.com/2007/10/multiple-left-joins-in-ms-access.html

It gives the error Invalid use of Null, which doesn’t make sense to me as I’m performing no null check etc. What is the problem here? I’m trying to pull a field in TableB to display (but did not put it in the select section yet).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:35:52+00:00Added an answer on June 16, 2026 at 4:35 am

    Access likes its parentheses. Add more parentheses around joins.

    The CLng function requires a non-null value. You can fix this with CLng(Nz(TableA.FieldA, "0")) >= 119593451. Though, if the field is numeric, why on earth would you make it text to begin with? This is a serious problem that I highly recommend fixing immediately (if at all possible) by changing the data type to a numeric one.

    But you have another problem. It is meaningless to LEFT JOIN to a table if you then in the WHERE clause put a condition, as you are doing in your query! Either change to an INNER JOIN or put your conditions on TableA into the ON clause of the LEFT JOIN. If Access won’t allow this syntax, then change to a derived table:

    SELECT
       TableA.FieldA As [Code],
       Count(TableA.FieldC) AS [Count]
    FROM
       (
          (
             (MainTable)
             LEFT JOIN (
                SELECT * FROM TableA
                WHERE
                   Clng(Nz(TableA.FieldA, "0")) >= 119593451
                   AND Clng(Nz(TableA.FieldA, "0")) <= 119593461
             ) TableA ON MainTable.FieldB = TableA.FieldB
          )
          LEFT JOIN TableB ON TableA.FieldD = TableB.FieldD
       )
    WHERE (((MainTable.DateOf)>=#1/1/2012#))
    GROUP BY TableA.FieldA;
    

    Note: adding WHERE TableA.FieldA IS NOT NULL may work but may not work. In Access it could be 100% safe but such a query in SQL Server would NOT be safe because there is no guaranteeing the order of conditions being applied. Obviously, in SQL Server you can convert to an integer even when NULL and there is no CLng function, but the point is still valid: do not get in the habit of relying on some imagined order of WHERE conditions protecting you from invalid type conversion: instead you must handle the invalid type conversion inside the expression that can error–that is best practice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query which works fine in SQL Server, but not in Access,
i have this sql query select * from table where name like ? but
I have this SQL query from the logs select content = 5%id%201=1 from pages
I've written this SQL query in MS Access: SELECT * FROM Students WHERE name
I have this SQL Query that pulls data from 3 tables. I am unable
I have this SQL query select case when AllowanceId is null then 2 else
I have this sql query: SELECT S.SEARCH, S.STATUS, C.TITLE AS CategoryName, E.SEARCH_ENGINES AS Engine,
I have this SQL query: SELECT DISTINCT tb.SERIAL_NUM, tb.REVISION_NUM, tb.JOB_NUM, tb.JOB_TOTAL, tb.TEST_PROC, tb.BOX_NUM, tb.TEST_BENCH,
Right now I have this SQL query which is valid but always times out:
Here is a sample access query which I have(query ref/name - abovequery) select column_date,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.