Bug in Access?

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/68885?pagenum=1
05 November 2025, 08:59

Topic


Jorrit787
Bug in Access?
27 August 2009, 02:49


I am using the SUM query below. When there are no records in the right table, instead of returning no records, the Recordset returns a record with the SUM'd field as Null.
Code:
SELECT SUM(something) AS sum_something FROM left_table RIGHT JOIN right_table ON
left_table.indexfield_id = right_table.indexfield_id WHERE right_table.wherefield = 'wherefield_value'
Instead of using If not rsSum.EOF = True I have to use If not rsSum("sum_something") <> Null angry
Is this a bug in Access?
Editquestion: Found this, but it pertains to MySql instead of Access, and it's from 2005.

 

Replies ...


ruirib
27 August 2009, 05:17


If there are no records, SUM returns NULL. It's like that not only in Access but also in SQL Server and MySQL.
Jorrit787
27 August 2009, 08:02


I did some more testing and it only returns Null when you are using a query with a join in it. Otherwise it just returns no records at all (which in my opinion it should do in both cases).
HuwR
27 August 2009, 13:14


try doing this

SELECT SUM(COALESCE(something,0)) AS sum_something FROM left_table RIGHT JOIN right_table ON
left_table.indexfield_id = right_table.indexfield_id WHERE right_table.wherefield = 'wherefield_value'

you query is doing exactly what it is designed to do, you need to convert any NULL values to 0 using the COALESCE before adding them together as SUM(NULL) is equal to NULL not 0
© 2000-2021 Snitz™ Communications