|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2011-02-22 : 15:18:04
|
execute the below .. Declare @tab table (a int, b varchar(10), c Numeric (4,2)) insert into @tab values (007,'C',15.00),(123,'D',10.00),(007,'D',5.00),(555,'D',10.00),(123,'D',5.00),(007,'D',10.00),(555,'F',15.00),(555,'C',5.00)select x.a,SUM(x.c) from @tab xwhere exists (select a from @tab where a=x.a group by a having COUNT(distinct b)>1)and b in ('c','d')group by x.aUnion allSelect A, sUM(0.00)from @tab where a not in (select x.afrom @tab xwhere exists (select a from @tab where a=x.a group by a having COUNT(distinct b)>1) and b in ('c','d')) AND b in ('c','d')Group by ajust to give you an idea |
 |
|