Given any SELECT
statement, I would like to wrap it with skip and take operators.
For instance, for Oracle I created this function:
public override string WrapSelectSqlWithPagination(string sql, int skipRows, int numberOfRows)
{
string innerSql = String.Format("select /* FIRST_ROWS(n) */ a.*, ROWNUM rnum from ({0}) a where ROWNUM <= {1}", sql, skipRows + numberOfRows);
return String.Format("select * from ({0}) where rnum > {1}", innerSql, skipRows);
}
It works perfectly.
I would like to do the same thing for SQL Server, is it possible?
Mind that I don't know anything about sorting in advance.
Thanks.
You can use this sql template to get the desired range of records for SQL.
Just replace the things in [] with your stuff. Remember to remove the []. And then use this in your method above.
Ok, I got it. It's probably very slow but it works:
Is there a better way to do this?