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 2005 Forums
 Transact-SQL (2005)
 Returning The Most Rated Record

Author  Topic 

skhan
Starting Member

1 Post

Posted - 2008-03-07 : 06:44:50
ALTER PROCEDURE dbo.GetMostRatedRecipe

(

@CurrentDate datetime

)

AS

SET NOCOUNT ON

SELECT *

FROM Recipe

WHERE TotalRating =

(SELECT MAX(TotalRating)FROM Recipe) AND published = 1 AND ReleaseDate <= @CurrentDate AND ExpireDate > @CurrentDate

This doesn't work good when the recipe having max total rating is not published & expired. I guess I need to first filter the recipes which are published & unexpired and then select the recipe having max total rating. But I don't know how to do that. Could anyone of you please help me doing this ?

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-03-07 : 07:18:04
Please post some sample data & the desired output.
Also read this to understand how to post your questions.

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page
   

- Advertisement -