zoukankan      html  css  js  c++  java
  • 把一般的查询sql处理成分页用的sql

            //// <summary>
            /// 把一般的查询sql处理成分页用的sql  用于sql2005以上
            /// </summary>
            /// <param name="sql">一般的sql</param>
            /// <param name="pn">当前页数</param>
            /// <param name="countPerPage">每一页的个数</param>
            /// <returns>返回分页用的sql</returns>
            public static string SQLFenyeChuli(string sql, int pn, int countPerPage)
            {
                try
                {
                    string topCount = (pn * countPerPage).ToString();//获取获取前多少条数据
                    string strAlreadyCount = ((pn - 1) * countPerPage).ToString();//获取已经查询的数据

                    string rtn = sql.Insert(6, " top " + topCount + " 0 as tempcolumn,");//在select后面插入分页用的数据
                    rtn = "select * from (select row_number() over (order by tempcolumn) temprow, * from (" + rtn + ")tt)t where temprow >" + strAlreadyCount;//row_number() 用于sql2005以上

                    return rtn;
                }
                catch
                {
                    return "";
                }
            }

  • 相关阅读:
    自定义函数
    内置函数
    炸裂函数explode
    -bash:ls:command not found,执行命令总是报找不到
    函数
    C#的lock用法
    获取客户端Ip地址方法
    Grunt基础
    常用Sql
    HandleBars
  • 原文地址:https://www.cnblogs.com/djian/p/1899472.html
Copyright © 2011-2022 走看看