To Select Nth Maximum Value using TOP key word, You can try the following Stored Procedure. CREATE PROCEDURE SP_SelectTopN (@N INT ) /****************************************/ /* Created By : Loganathan V */ /* Created On: 21-Sep-2010, Tuesday */ /* Purpose : To Get the N th Top Value from*/ /* Recordset. */ /* How to : EXEC SP_SelectTopN */ /* : EXEC SP_SelectTopN 4 */ /****************************************/ AS BEGIN DECLARE @P INT SELECT @P=@N SELECT TOP 1 * FROM ( SELECT TOP (@P) * FROM SALARYTABLE ORDER BY SALARY DESC ) AS TOPNRECORDS ORDER BY SALARY ASC END To Run the Stored Procedure follow this: ...
An enthusiastic software developer