• quote:


    ...but SQL Server doesn't like it...


    I know. Annoying, isn't it, that you can't use a variable in the TOP clause...you have to use sp_executesql:

    
    
    DECLARE @n INT
    DECALRE @sql NVARCHAR(2000)
    SET @n = 76
    SET @sql = N'select top 1 salary from (select top ' + @n + ' employeeId from employee
    order by salary asc) a
    order by salary desc'
    EXEC sp_executesql(@sql)

    Cheers.