Friday, June 22, 2012

select top x % from a table

I didn't know you could do this. Thanks to @shark at dba.stackexchange, now I do:

Source


declare @top_val int = 30
select top (@top_val) percent
    col1,
    col2,
    col3from yourTable