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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Display latest date only

Author  Topic 

Delinda
Constraint Violating Yak Guru

315 Posts

Posted - 2009-04-06 : 10:41:12
Hi,

Let's say i've following table,
tblRegDte
AssetID | ReNewDte | EndDte
-------------------------------------
1631 | 4/13/2005 | 4/12/2009
1631 | 4/13/2001 | 4/12/2005
1223 | 7/13/2005 | 7/12/2009
1629 | 4/13/1998 | 4/12/2002
1629 | 4/13/2006 | 4/12/2010
1629 | 4/13/2002 | 4/12/2006
1622 | 4/13/2002 | 4/12/2006
....
....

How SQL look's like to display only latest date on EndDte on each AssetID.

My expected result as follow,
AssetID | ReNewDte | EndDte
-------------------------------------
1631 | 4/13/2005 | 4/12/2009
1223 | 7/13/2005 | 7/12/2009
1629 | 4/13/2006 | 4/12/2010
1622 | 4/13/2002 | 4/12/2006
....
....

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-04-06 : 10:47:53
Look up MAX() in Books Online.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-06 : 10:50:57
select * from your_table as t
where EndDte=(select max(EndDte) from your_table where AssetID=t.AssetID and ReNewDte=t.ReNewDte)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

dsindo
Starting Member

45 Posts

Posted - 2009-04-10 : 14:58:03
select AssetID, max(ReNewDte) as ReNewDte, max(EndDte) as EndDte from tblRegDte group by AssetID
Go to Top of Page

dsindo
Starting Member

45 Posts

Posted - 2009-04-10 : 15:07:10
select * from tblRegDte a
inner join
(
select assetid, max(enddte) as enddte from tblRegDte group by assetid
) b on a.assetid=b.assetid and a.enddte=b.enddte
Go to Top of Page
   

- Advertisement -