Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir,

i have one month record, i want to filter top 4 record what ever date that month



thanks n advance
Posted
Comments
Amir Mahfoozi 3-Dec-11 2:47am    
Please provide an example.

Try
select top (4) from table order by datecolumn desc
 
Share this answer
 
Comments
[no name] 3-Dec-11 21:53pm    
4. you forgot something
Try:
SQL
SELECT TOP 4 * FROM myTable WHERE DATEPART(year, @MATCHDATE)=DATEPART(year,[date]) AND DATEPART(month, @MATCHDATE)=DATEPART(month,[date]) ORDER BY [date]
The WHERE condition just allows you to provide a parameter to select the date - if your table only holds one month, then you can omit it.
 
Share this answer
 
Try this instead:

SQL
SELECT TOP 4 * FROM [tablename] ORDER BY date_field des


Please mark as answer and vote 5 if this solved your problem

Regards,
Eduard
 
Share this answer
 
Try this instead:

SQL
SELECT TOP 4 * FROM [tablename] ORDER BY date_field desc


Please mark as answer and vote 5 if this solved your problem

Regards,
Eduard
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900