Maybe you lost formatting when you posted your expected output. You have to put code tags around it to retain spacing.How about this:declare @t table (code char(1), billamt int, allowamt int)insert into @t values('a', 20, 15)insert into @t values('a', -15, 15)insert into @t values('b', 7, -12)insert into @t values('c', 4, -17)insert into @t values('d', 37, -30)select code, countof = count(billamt) + count(allowamt), negba = sum(case when billamt < 0 then 1 else 0 end), posba = sum(case when billamt > 0 then 1 else 0 end), negaa = sum(case when allowamt < 0 then 1 else 0 end), posaa = sum(case when allowamt > 0 then 1 else 0 end)from @tgroup by codeTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog