SQL 分页 SQL SERVER 2008

 

public IList<UserInfo> GetPageList(int pageSize, int pageIndex, out int totalItemCount)

{

    var totalSql = "SELECT COUNT(1) FROM UserInfo";

    Object result = GetScalar(totalSql); 

    totalItemCount = result == null ? 0 : ConvertHandler.ToInt32(result);

    var sql = string.Format(@"SELECT u2.n, U.* FROM UserInfo U,

                            (SELECT TOP {0} row_number() OVER (ORDER BY Name DESC) n, CODE FROM UserInfo)

                             u2 WHERE U.CODE = u2.CODE AND u2.n >= {1} ORDER BY u2.n ASC", 

                            ((@pageIndex - 1) * @pageSize) + @pageSize, ((@pageIndex - 1) * @pageSize) + 1);

    return GetList(sql); 

}

 

SQL 分页 SQL SERVER 2008

网上选了个分页的SQL,凑合够用。程序本地,数据库万网空间附带的MSSQL 2008,如果数据库放本地不知道能快多少。

你可能感兴趣的:(SQL Server 2008)