To keep it simple, I have a large SQL table with 3 fields: Date, Account & Value.
I want the sum of values for each account for a defined time period.
This is simple using SUM() & GROUP BY.
However, there may not be any activities for some accounts during the period, in which case I want 0 returned. What happens is that such accounts are not returned.
I have searched & tried many solutions to no avail - ISNULL, COALESCE, CASE, etc. The simplified code is:
The Account field is integer numeric, if that helps
I suspect that the WHERE condition limits the SUM function so that there are no NULL rows generated. How do I get round this ?
The actual database is large so I would not want import it in total.
I want the sum of values for each account for a defined time period.
This is simple using SUM() & GROUP BY.
However, there may not be any activities for some accounts during the period, in which case I want 0 returned. What happens is that such accounts are not returned.
I have searched & tried many solutions to no avail - ISNULL, COALESCE, CASE, etc. The simplified code is:
Code:
SELECT Date, Account, SUM(Value)
FROM Database
WHERE date BETWEEN 'Date1' AND 'Date2'
GROUP BY Account
ORDER BY Account
The Account field is integer numeric, if that helps
I suspect that the WHERE condition limits the SUM function so that there are no NULL rows generated. How do I get round this ?
The actual database is large so I would not want import it in total.