Not sure really..but something using CTE's would work.Create table #foo([User] char(2),MemberID char(5),ClubID char(2),FamilyID char(2),MemAmnt money,AdditionalAmnt money NULL)INSERT INTO #fooSELECT 'U1', 'A1234', 'C1', 'F1' ,100, 10 UNIONSELECT 'U1', 'A1234', 'C7', 'F2' ,150, 10 UNIONSELECT 'U1', 'A2233', 'C2', 'F3' ,150, NULL UNIONSELECT 'U2', 'A1244', 'C2', 'F4' ,200, 20 UNIONSELECT 'U2', 'A1245', 'C3', 'F5' ,200, NULL UNIONSELECT 'U2', 'A1246', 'C4', 'F6' ,100, 10 UNIONSELECT 'U3', 'A1251', 'C5', 'F1' ,100, NULL UNIONSELECT 'U3', 'A1252', 'C6', 'F1' ,100, NULL ;WITH t1 AS (SELECT [USER],[MEMBERID],SUM(MemAmnt) as TotalContribution FROM #foo WHERE AdditionalAmnt >0 GROUP BY [USER],[MEMBERID]) , t2 AS (SELECT [USER],COUNT(*) as NumMembers FROM #foo GROUP BY [USER])SELECT #foo.* ,TotalContribution = COALESCE(t1.TotalContribution,0) ,TotalContributors =t2.NumMembers ,giftValue = CASE WHEN t1.TotalContribution between 1 and 100 then '01' WHEN t1.TotalContribution between 101 and 300 then '03' WHEN t1.TotalContribution between 301 and 500 then '10' WHEn t1.TotalContribution> 500 then '20' ELSE NULL ENDFROM #foo LEFT JOIN t1 on #foo.[USER] = t1.[USER] and #foo.MemberID = t1.MemberID LEFT JOIN t2 on #foo.[USER] = t2.[USER]Drop Table #foo
Poor planning on your part does not constitute an emergency on my part.