Urggggg! I\'ve been struggling with this for a long time! I can do it with MySQL so easy but not with SQL Server :(
Here are the simplified tables which should be jo
You can use the methods from the following class
internal class PagingHelper
{
public static String ParseQueryForPagingAndSorting(String strSQL, string SortExpression, int StartIndex, int EndIndex)
{
if (String.IsNullOrEmpty(SortExpression))
SortExpression = " (select 0)";
StringBuilder sb = new StringBuilder();
sb.Append("select * from (");
sb.Append(" select ROW_NUMBER() OVER (ORDER BY " + SortExpression + ") AS row_num,");
int index = strSQL.ToLower().IndexOf('t', 0);
sb.Append(strSQL.Substring(index + 2));
sb.Append(")");
sb.Append(" AS TempTable");
sb.Append(" where row_num>=" + StartIndex.ToString() + " AND row_num<=" + EndIndex.ToString());
return sb.ToString();
}
public static String ParseQueryForCount(String strSQL)
{
StringBuilder sb = new StringBuilder();
sb.Append("select count(*) from");
sb.Append("(");
sb.Append(strSQL);
sb.Append(")");
sb.Append(" AS TempTable");
return sb.ToString();
}
}