Sql分页

int maxNum = pageIndex * pageSize;
int minNum = (pageIndex - 1) * pageSize + 1;
if (tabstr.ToLower() == “view_mi_notpublish”)
{
if (publish == “1”)
{

                tabstr = "( select * from view_mi_notpublish where user_name='" + username + "' union all select * from view_mi_publish )";
            }
            else
            {
                tabstr = "( select * from VIEW_MI_NEWEST_VERSION where user_name='" + username + "' order by mi_list_pub_date desc  )";
            }

        }


        string countNumsql = string.Format("select Count(1) as totalnum from {1} {0}", where, tabstr);
        DataSet listCount = OracleHelper.Query(countNumsql);
        DataTable listtbcount = listCount.Tables[0];
        msg = "";
        if (listtbcount.Rows.Count > 0)
        {
            msg = listtbcount.Rows[0]["TOTALNUM"].ToString();
        }
        string sql = string.Format(@"SELECT * FROM (SELECT MI_LIST_ID,
                 MI_LIST_NUM,
                 MI_LIST_DESC,
                 MI_LIST_MODEL,
                 MI_LIST_VERSION_DESC,
                 MI_LIST_ECN_NO,
                 MI_LIST_VERSION_DATE,
                 MI_LIST_VERSION_SIGNATURE,
                 MI_LIST_VERSION_NUM,
                 MI_LIST_TYPE_ID,
                 Project_Code,
                 Mi_Title,
                 MI_LIST_TYPE_NAME,
                 MI_LIST_REF,
                 MI_LIST_STATUS,
                 CELL_TECH_ID,
                 CELL_TECH_NAME,
                 MI_LIST_FLAG,
                 MI_LIST_EDITOR,
                 MI_LIST_PUB_DATE,
                 MI_LIST_DEADLINE,
                 USER_NAME,
                 USER_FULLNAME,
                 USER_DEPARTMENT,
                 USER_NAME_EN,
                 DUE_DATE,
                 CUSTOMER_ID,
                 ROWNUM rn FROM
         (SELECT * FROM {3} {0} )WHERE ROWNUM<= {1}) t2
           WHERE T2.rn >= {2}", where, maxNum, minNum, tabstr);

你可能感兴趣的:(C#,SQL,SERVER)