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 |
|
rupspawar
Starting Member
3 Posts |
Posted - 2006-11-16 : 06:06:06
|
| Create Table #tbGtrade (CId INT, TDate Datetime, Grade varchar(1))insert into #tbGtradeselect 217 as CompanyId , '2006-11-09 00:00:00.000' as tradedate ,'B' as Recommunionselect 217 as CompanyId , '2006-10-09 00:00:00.000' as tradedate ,'s' as Recommunionselect 221 as CompanyId , '2006-10-10 00:00:00.000' as tradedate ,'b' as Recommunionselect 337 as CompanyId , '2006-10-10 00:00:00.000' as tradedate ,'b' as Recomm select * from #tbGtradeCId Date Grade 217 2006-11-09 00:00:00.000 B221 2006-10-10 00:00:00.000 b337 2006-10-10 00:00:00.000 b217 2006-10-09 00:00:00.000 sI tried using following query SELECT CId , MAX(TDate) AS [Date], MAX(Grade)as gradeFROM #tbGtradegroup by CIdDesired ResultsCId Date Grade 217 2006-11-09 00:00:00.000 B221 2006-10-10 00:00:00.000 b337 2006-10-10 00:00:00.000 bbasically, I want one a corresponding grade for max date of each CId.Thanku All for your help and time.Rupesh.. |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-11-16 : 06:35:55
|
How about this?select CID, tdate, Gradefrom #tbGtrade t1where tdate = (select max(tdate) from #tbGtrade t2 where t2.CID = t1.CID)order by CID Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
|
|
|
|
|