It was crappy Monday and I can't think straight. Can someone help me figure out how to group / summarize the returned rows so that there is only one instance of the AssessorParcelNumber class?
So, instead of the following result set:
140-31-715-164 3545 2004-09-14 00:00:00.000 1665.00 0.00 0.00 1665.00
140-31-715-164 3545 2004-09-14 00:00:00.000 0.00 534.00 0.00 534.00
140-31-715-037 3546 2004-03-11 00:00:00.000 120.00 0.00 0.00 120.00
140-31-715-037 3546 2004-03-11 00:00:00.000 0.00 0.00 0.00 0.00
I get this instead:
140-31-715-164 3545 2004-09-14 00:00:00.000 1665.00 534.00 0.00 2199.00
140-31-715-037 3546 2004-03-11 00:00:00.000 120.00 0.00 0.00 120.00
Help! Thank!
select
u.AssessorParcelNumber,
c.CollectionKey AS [r_number],
c.Closed,
CASE cd.Name1 WHEN 'Association'
THEN CONVERT(dec(18,2),sum(t.Amount - t.AppliedAmount)) ELSE 0 END AS [assoc_balance],
CASE cd.Name1 WHEN 'RRFS'
THEN CONVERT(dec(18,2),sum(t.Amount - t.AppliedAmount)) ELSE 0 END AS [rr_balance],
CASE cd.Name1 WHEN 'RRFS' THEN 0 WHEN 'Association' THEN 0
ELSE CONVERT(dec(18,2),sum(t.Amount - t.AppliedAmount)) END AS [_balance],
CONVERT(dec(18,2),SUM(t.amount - t.AppliedAmount)) AS [balance]
from
Unit u with(nolock)
left outer join [collection] c with(nolock) on u.UnitKey = c.UnitKey
left outer join TransactionDetail t with(nolock) on c.CollectionKey=t.CollectionKey
left outer join TypeCode tc with(nolock) on t.PostType = tc.PostType
left outer join CodeData cd with(nolock) on tc.Category = cd.Code2 and Code1=5
where
t.Credit = 0
and t.Voided = 0
group by
u.AssessorParcelNumber, c.CollectionKey, c.closed, cd.Name1
order by
c.CollectionKey,
cd.Name1;
source
share