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
 General SQL Server Forums
 New to SQL Server Programming
 Max

Author  Topic 

BendJoe
Posting Yak Master

128 Posts

Posted - 2010-05-19 : 11:32:05
DocID UserID Date
400005564 26 2010-03-15 08:42:10.767
400005564 27 NULL
400005564 40 2010-03-11 00:00:00.000

I need the UserID for the row which has the max (date) from the above data where DocID will be a parameter @docID.
Thanks

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-05-19 : 11:46:35
If you are using SQL Server 2005 and above.
select * from 
(
select row_number () over (partition by DocID order by Date desc) as seq, * from table1
) t
where t.seq = 1 and t.DocID = @docID
Go to Top of Page
   

- Advertisement -