日期:2014-05-17  浏览次数:20483 次

sql2000使用ROW_NUMBER
public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("SELECT * FROM ( ");
strSql.Append(" SELECT ROW_NUMBER() OVER (");
if (!string.IsNullOrEmpty(orderby.Trim()))
{
strSql.Append("order by T." + orderby );
}
else
{
strSql.Append("order by T. desc");
}
strSql.Append(")AS Row, T.* from ExamSetting T ");
if (!string.IsNullOrEmpty(strWhere.Trim()))
{
strSql.Append(" WHERE " + strWhere);
}
strSql.Append(" ) TT");
strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
return DbHelperSQL.Query(strSql.ToString());
}
使用sql2000怎么写??

------解决方案--------------------
笔误,少了个order
SQL code

SELECT * FROM   
( 
SELECT TOP 10 * FROM 
(SELECT TOP 20 * FROM ExamSetting WHERE 1=1 ORDER BY id) T order BY id DESC 
) TT ORDER BY id