Search code examples
sqlsql-server-2014

How to select top multiple of 10 entries?


How to select top multiple of 10 entries?

I have a data in SQL table that is meaningful if only seen as bunch of 10 entries. I want to write a query that does this for ex. Select top 10*n from table where condition.

If for ex. 53 entries satisfy condition, I want only 50 to be seen and last 3 to be discarded.

Plz help. Kbv


Solution

  • How about:

    declare @rows int;
    set @rows = ((select count(*) from table where condition)/10)*10
    
    select top @rows * from table where condition