Starting with a simple table that contains
Date,Result,Account
where there can be more than one entry for a date&account combination and where there are some dates without entries for all accounts.
I'd like to output:
Date, Account1 sum(Result), Account2 sum(Result), etc...
In cases where there is data for one Account but not another Account for a certain date, I want to ensure there is still an entry for that date. Currently my query does the above but only creates an entry when there is a value stored for all Accounts selected.
Select a.Date
,isnull(Sum(a.Result),0) as Total_Account1
,isnull(Sum(b.Result),0) as Total_Account2
From MyTable a
join MyTable b on a.Date = b.Date
Where a.Account = 'Account1'
and b.Account = 'Account2'
Group by a.Date,b.Date
Order By a.Date