declare \@limit int declare \@offset int set \@offset = $offset; set \@limit = $limit; declare \@idxini int declare \@idxfim int select \@idxfim = \@offset * \@limit select \@idxini = \@idxfim - (\@limit-1); WITH paging AS ( SELECT ROW_NUMBER() OVER (order by table_ID) AS rowid, * FROM table ) select * from paging where rowid between \@idxini and \@idxfim order by rowid; ; END_ROW2