Bug in Access? - نوشته شده در (975 Views)
Average Member
Jorrit787
مطلب: 681
681
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.
 پیش‌فرض مرتب‌سازی برای تاریخ DESC به معنی جدیدترین است  
 تعداد در صفحه 
نوشته شده در
Snitz Forums Admin
ruirib
مطلب: 26364
26364
If there are no records, SUM returns NULL. It's like that not only in Access but also in SQL Server and MySQL.
نوشته شده در
Average Member
Jorrit787
مطلب: 681
681
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).
نوشته شده در
Forum Admin
HuwR
مطلب: 20611
20611
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
 
شما باید یک متن وارد کنید