Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
omega1983
Starting Member
40 Posts |
Posted - 2010-06-30 : 16:35:45
|
select -- f.giftacctno,f.giftacctnm,sum(f.giftamount)as Amtgiftacctno,max(giftacctnm) as AcctName,sum(giftamount)as Amt,max(gifteffdat)as GiftEffDatefrom gifts with(nolock)where giftclass2 = 'Foll'and giftclass1 = 'v'and gifttype in ('bj','bv','b','gj','g','gv','yj','y','yv')and gifttdeduc >0and gifttender in ('c','cc','dd','pd')and datediff(month, gifteffdat, getdate()) <= 2 --current month beginand datediff(month, gifteffdat, getdate()) = 2 --current month end--select distinct table_code,table_val--from dbo.tendergroup by giftacctno,giftacctnm,giftamount--,f.gifteffdatHere is sample outputAccountNumber AcctName Amt Date00111 Business 100 2010063000111 Business 200 2010063000111 Business 100 2010062800112 Engineering 100 20100629I want the output to beAccountNumber AcctName Amt Date00111 Business 300 2010063000111 Business 100 2010062800112 Engineering 100 20100629In other words I want Business to be consolidated if the account number and Date are the same |
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2010-06-30 : 16:41:21
|
what happens if you removed giftamount from the group by<><><><><><><><><><><><><><><><><><><><><><><><><>If you don't have the passion to help people, you have no passion |
 |
|
SD_Monkey
Starting Member
38 Posts |
Posted - 2010-07-01 : 03:25:07
|
you dont need to use the max... use order by for sorting data value..A maze make you much more better |
 |
|
|
|
|
|
|