'Look for ``LIMIT`` and OFFSET in a select statement, and if
so tries to wrap it in a subquery with ``row_number()`` criterion.'

def visit_select(self, select, **kwargs):

    if (select._offset and (not getattr(select, '_mssql_visit', None))):
        if (not select._order_by_clause.clauses):
            raise exc.CompileError('MSSQL    requires    an    order_by    when    using    an    offset.')
        _offset = select._offset
        _limit = select._limit
        _order_by_clauses = select._order_by_clause.clauses
        select = select._generate()
        select._mssql_visit = True
        select = select.column(sql.func.ROW_NUMBER().over(order_by=_order_by_clauses).label('mssql_rn')).order_by(None).alias()
        mssql_rn = sql.column('mssql_rn')
        limitselect = sql.select([c for c in select.c if (c.key != 'mssql_rn')])
        limitselect.append_whereclause((mssql_rn > _offset))
        if (_limit is not None):
            limitselect.append_whereclause((mssql_rn <= (_limit + _offset)))
        return self.process(limitselect, iswrapper=True, **kwargs)
    else:
        return compiler.SQLCompiler.visit_select(self, select, **kwargs)
