SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Finding the Nth Maximal Value

By iecdba,

This procedure gets a tablename, column and an integer number N as parameters
and finds the Nth maximum value of the column's value in a table

for example :  running it with 'products', 'UnitPrice' , 13 ,  @res

will get the 13TH largest value of unitprice from products
is no such N exist an error message is printed.

Total article views: 236 | Views in the last 30 days: 2