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 "";
                }
            }

  • 相关阅读:
    java jmap,jstat等工具的使用
    jvm 参数配置
    python NameError: name 'false' is not defined
    aiflow Global variable explicit_defaults_for_timestamp needs to be on (1) for mysql
    TX 笔试题总结
    POJ 3140 Contestants Division
    POJ 1018 Communication System
    POJ 3260 The Fewest Coin
    Leetcode: Median of two sorted Array
    基础知识 (二)
  • 原文地址:https://www.cnblogs.com/djian/p/1899472.html
Copyright © 2011-2022 走看看