Question

I am looking for a way to return 0 as result for a SQL Query in MS Access when no rows are returned. Following is my query:

SELECT SUM(IIF(TotalCount =  null, 0, TotalCount)) AS MailCount  FROM MailReport WHERE [SendDate]=#2/12/2013# and MailerID=1

Here the Column TotalCount is number type and works fine for a query that returns some result. But in case for example date 2/13/2013 has no records, it would simply return a blank row that is nither 0 nor null. How do I return a 0 for this row.

Was it helpful?

Solution

SELECT  SUM(IIF([SendDate]=#2/12/2013# AND MailerID = 1, IIF(TotalCount =  null, 0, TotalCount), 0)) AS MailCount  
FROM    MailReport 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top