Get Top 3rd salary using MS SQL server

You can get any number of Top salary by using below query

WITH CTE AS
(
    SELECT EmpID, EmpName, EmpSalary,
           RN = ROW_NUMBER() OVER (ORDER BY EmpSalary DESC)
    FROM dbo.Salary
)
SELECT EmpID, EmpName, EmpSalary
FROM CTE
WHERE RN = @NthRow
If somebody ask for Top 3rd salary, then i'll replace 3 to @NthRow then i'll execute query. and then i'll get top 3rd salary.  

Comments

Popular posts from this blog

Tree view in winforms using c#

how to Replace null value with 0 Using C#

how to fetch all HTML Table Records and modify all records accordingly using jquery and Javascript