Server 2000/2005 分页

本文介绍了三种在SQL Server 2000/2005中实现分页查询的方法,包括使用NOT IN、子查询及ROW_NUMBER()函数等技术手段,帮助开发者更高效地进行数据检索。
方法1:

适用于 SQL Server 2000/2005

SELECT TOP 页大小 *

FROM table1

WHERE id NOT IN

          (

          SELECT TOP 页大小*(页数-1) id FROM table1 ORDER BY id

          )

ORDER BY id

 

方法2:

适用于 SQL Server 2000/2005

SELECT TOP 页大小 *

FROM table1

WHERE id >

          (

          SELECT ISNULL(MAX(id),0)  

          FROM  

                (

                SELECT TOP 页大小*(页数-1) id FROM table1 ORDER BY id

                ) A

          )

ORDER BY id  

方法3:

适用于 SQL Server 2005

SELECT TOP 页大小 *  

FROM  

        (

        SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNumber,* FROM table

1

        ) A

WHERE RowNumber > 页大小*(页数-1)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>机器码管理</title> <link rel="stylesheet" href="/static/css/main.css" type="text/css"> <link rel="stylesheet" href="/static/css/machine.css" type="text/css"> <script src="/static/js/jquery-1.11.3.js"></script> <script src="/static/js/tools.js?v=<%= System.currentTimeMillis()%>"></script> <script src="/static/js/machine.js?v=<%= System.currentTimeMillis()%>"></script> </head> <body style="width: 990px"> <div id="container"> {% include 'top.html' %} {% include 'left.html' %} <div id="right"> <div id="top_func"> <form action="/machine_search/" method="get" style="display: inline-block"> <input type="text" name="input_search" placeholder="单位/账号" id="input_search"> <input type="submit" value="搜索" class="btn" id="btn_search"> </form> </div> <div class="div_table"> <table id="item_table"> <tr id="table_th"> <td class="col0">序号</td> <td class="col1">申请单位</td> <td class="col3">机器码</td> <td class="col4">授权时间</td> <td class="col11">操作</td> </tr> {% for data in models %} <tr class="update_datas"> <td class="col0">{{ forloop.counter |add:from_num }}</td> <td class="col1">{{ data.campany.name }}</td> <td class="col3">{{ data.mac}}</td> {% if data.create_date == null %} <td class="col4"></td> {% elif data.create_date == "" %} <td class="col4"></td> {% else %} <td class="col4">{{ data.create_date|date:"Y-m-d H:i:s" }}</td> {% endif %} <td class="col11"> <span style="display: none">{{ data.id }}</span> {% if data.is_active %} <a class="btn_active">已激活</a> {% else %} <a class="btn_active">未激活</a> {% endif %} <a class="btn_delete">删除</a> </td> </tr> {% endfor %} </table> </div> <div id="paging"> 共有 <span id="total_num">{{ total_num }}</span> 条记录,当前第 <span id="local_page">{{ local_page }}</span>/ <span id="total_page">{{ total_page }}</span> 页 <div> <input type="button" value="首页" class="btn" id="btn_firstpage"> <input type="button" value="上一页" class="btn" id="btn_lastpage"> <input type="button" value="下一页" class="btn" id="btn_nextpage"> <input type="button" value="尾页" class="btn" id="btn_endpage"> &nbsp;&nbsp;转到第&nbsp;&nbsp;<input type="text" id="targetpage">&nbsp;&nbsp;页&nbsp;&nbsp; <input type="button" value="跳转" class="btn" id="btn_targetpage"> </div> </div> </div> </div> </body> </html>以上代码为什么在进行上一页下一页时授权时间会消失进行单位查询时会报错Server Error (500),为什么呢,怎么优化,上面代码需要优化吗,优化后的代码是什么
10-25
function initTable_work() { // 獲取當前顯示的stage var wipSource = []; $.ajax({ url: 'docmanage.aspx?type=task/stageJson', async: false, type: "get", data: {}, success: function (data, status) { for (var item of data){ wipSource.push({value:item,text:item}) } } }); // 获取PDE人員 var pdeSource = []; $.ajax({ url: 'docmanage.aspx?type=task/pdeJson', async: false, type: "get", data: {}, success: function (data, status) { for (var item of data){ pdeSource.push({value:item.value,text:item.text}) } } }); //獲取發文難度 var docDifficult=[]; $.ajax({ url: 'docmanage.aspx?type=task/docDifficult', async: false, type: "get", data: {}, success: function (data, status) { for (var item of data){ docDifficult.push({value:item,text:item}) } } }); // 預設模式:<i class="bi bi-gear m-l-5"> // 手動模式:<i class="bi bi-wrench m-l-5"></i> // 預估模式:<i class="bi bi-bell m-l-5"></i> // 獲取係統中的wip_mode的值 默認是預設模式 var wip_mode = '<i class="bi bi-gear m-l-5" value="1" title="預設" onclick=updateWipMode(1)>' var process_mode='<i class="bi bi-arrow-clockwise" onclick=freshProcess()>' $.ajax({ url: 'docmanage.aspx?type=task/getWipMode', async: false, type: "get", data: {}, success: function (data, status) { // 手動模式: if (data[0]['mode'] === '2'){ wip_mode = '<i class="bi bi-wrench m-l-5" value="2" title="手動" onclick=updateWipMode(2)>' } // 預估模式: if (data[0]['mode'] === '3'){ wip_mode = '<i class="bi bi-bell m-l-5" value="3" title="預估" onclick=updateWipMode(3)>' } // 存儲wip_mode的值 localStorage.setItem('wip_mode',data[0]['mode']) } }); // 查詢參數 var savedQueryParams = JSON.parse(localStorage.getItem('queryParams')) || {}; var columnArr = [ { field: 'state', checkbox: true, align: 'center', valign: 'middle' }, { title: '操作', field: 'operate', align: 'center', switchable:false, align: 'center', events: window.operateEvents_work, formatter: operateFormatter_work }, { title: '任務No.', field: 'doc_no', align: 'center', switchable:false, sortable: true }, { title: '&nbsp;&nbsp;&nbsp;&nbsp;日期&nbsp;&nbsp;&nbsp;&nbsp;', field: 'create_time', align: 'center', switchable:false, sortable: true }, { title: '廠內料號', field: 'fact_partnum', switchable:false, sortable: true, escape: true, align: 'center' }, { title: '疊構', field: 'doc_products', switchable:false, sortable: true, escape: true, align: 'center' }, { title: '特殊設計', field: 'special_design', switchable:false, sortable: true, escape: true, align: 'center' }, { title: '產品', field: 'doc_product', switchable:false, sortable: true, escape: true, align: 'center' }, { title: '發文難度', field: 'difficulty', switchable:false, sortable: true, escape: true, editable: { noEditFormatter: function (value, row, index, field){ return false; }, source: docDifficult, type: 'select', escape:true, title: '發文難度', validate: function (v) { if (!v) return '發文難度不能为空!'; } }, align: 'center' },{ title: 'PDE', field: 'pde_finish_user', switchable:false, escape:true, sortable: true, editable: { noEditFormatter: function (value, row, index, field){ return false; }, source: pdeSource, type: 'select', escape:true, title: 'PDE人員', validate: function (v) { if (!v) return 'PDE人員不能为空!'; } }, align: 'center' }, { title: '&nbsp;&nbsp;&nbsp;&nbsp;備註 &nbsp;&nbsp;&nbsp;&nbsp;', field: 'explain', switchable: false, escape:true, sortable: true, editable: { noEditFormatter: function (value, row, index, field){ return false; }, type: 'textarea', escape:true, title: '備註', validate: function (v) { if (!v) return '備註不能为空!'; } }, formatter: function (value) { return '<span data-toggle="tooltip" title="' + value +'">' + value.substring(0, 10) +'</span>' }, align: 'center' },{ title: '流程'+process_mode, field: 'doc_process', switchable:false, sortable: true, align: 'center' }, { title: 'WIP'+wip_mode, field: 'wip', switchable:false, sortable: true, editable: { noEditFormatter: function (value, row, index, field){ return false; }, type: 'select', escape:false, title: 'WIP', source: wipSource, validate: function (v) { if (!v) return 'WIP不能为空!'; } }, align: 'center' }, { title: '上傳情形', field: 'uploadScenarios', switchable:false, sortable: true, align: 'center', formatter: formatter_uploadScenarios }, { title: '工單檔案', field: 'uploadArchive', switchable:false, sortable: true, align: 'center', visible: false }, { title: '工單完成狀態', field: 'uploadfinishStatus', switchable:false, sortable: true, align: 'center', visible: false },{ title: '工單備註', field: 'uploadRemark', switchable:false, sortable: true, align: 'center', visible: false }, { title: '狀態', field: 'stages_status', switchable:false, sortable: true, align: 'center', formatter: formatter_status_vb }, { title: '發文', field: 'stage_type', switchable:false, align: 'center', formatter: function(value){return '<span>'+value+'&nbsp;<i class="bi bi-info-circle"></i></span>'}, events:window.operateEvents_work }] //從數據庫中獲取列 根據fact_no 獲取不同的stage $.ajax({ url: 'docmanage.aspx?type=task/stageJson', async: false, type: "get", data: {}, success: function (data, status) { $.each(data, function (key, value) { columnArr.push({ title: value, field: value, align: 'center', valign: 'middle', events:checkboxEvents_work, formatter: checkboxFormatter_work }); }); } }); $table_work.bootstrapTable('destroy').bootstrapTable({ url:'docmanage.aspx?type=task/dataJson', method:'get', cache: false, showColumnDynamic:false,//篩選設定 該項為自定義的 showColumns:true,//顯示列 showRefresh:true,//顯示刷新按鈕 striped: false,//是否顯示行間隔色 toolbar:"#queryForm_docwork", pageNumber: 1,//初始化第一頁 pagination: true,//是否分頁 sidePagination : 'server',//server:服务器端分页|client:前端分页 pageSize : 20,//单页记录数 pageList:[10,20,50],//分页步进值 sortable:true, sortOrder:'asc', height: document.documentElement.clientHeight-200, showExport: true, Icons : 'glyphicon-export', exportDataType: 'all', //选择导出数据的范围,默认basic:只导出当前页的表格数据;all:导出所有数据;selected:导出选中的数据 //导出文件类型,因为导出png文件时会出现忽略的列也显示;导出PDF文件出现中文乱码的问题,所以根据需要只支持Excel文件类型即可 exportTypes: ['csv'], //['json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'pdf'] //导出设置 exportOptions: { ignoreColumn: [0], //忽略某一列的索引 //重新format數據 onCellData: function(cell, rowIndex, colIndex, rowData, cellData){ //如果rowData 以...結尾 說明內容被截斷 從show-info中取出信息 if(rowIndex >= 1 && rowData.endsWith('...')){ return $(cell[0]).children().children().attr('show-info') } // return rowData; if(!isNaN(rowData)){ return "\u200B"+rowData ; } else{ return rowData; } },如何在导出时显示uploadArchive、uploadfinishStatus、uploadRemark栏位
最新发布
11-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jarry.liu

如果对您有帮助,鼓励下博主吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值