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
 Restricting the Rows

Author  Topic 

GaneshRamanan
Starting Member

40 Posts

Posted - 2011-02-02 : 06:13:11
Hi,

I wants to restrict below rows, i need only 5 rows from Each parameterid based on recent dates.

ParameterID Parameter Date SubParameter
2 Anaemia 2011/01/28 Yes
2 Anaemia 2011/01/27 Yes
2 Anaemia 2011/01/26 Yes
2 Anaemia 2011/01/25 Yes
2 Anaemia 2011/01/24 Yes
3 Pedal Edema 2011/02/03 Yes
3 Pedal Edema 2011/01/28 Yes
3 Pedal Edema 2011/01/27 Yes
3 Pedal Edema 2011/01/26 Yes
3 Pedal Edema 2011/01/25 Yes
3 Pedal Edema 2011/01/24 Yes
4 CVS 2011/02/03 Normal
4 CVS 2011/01/28 Normal
4 CVS 2011/01/27 Normal
4 CVS 2011/01/26 Normal
4 CVS 2011/01/25 Normal
4 CVS 2011/01/24 Normal

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-02-02 : 07:04:13
select ParameterID, Parameter, Date, SubParameter from
(select row_number() over (partition by ParameterID order by Date DESC) as rownum,* from Your_Table)dt
where rownum < 6


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

GaneshRamanan
Starting Member

40 Posts

Posted - 2011-02-02 : 08:31:20
Hi,

Thanks for your support.

Ganesh
Go to Top of Page
   

- Advertisement -