当前位置: 代码迷 >> Sql Server >> MS SQL分页有关问题
  详细解决方案

MS SQL分页有关问题

热度:25   发布时间:2016-04-27 14:45:54.0
MS SQL分页问题
select top 20 nEquipmentId,strEntName,strEquipmentType,strRegCode,strProduceCorp,strEquipmentModel,strEquipmentNumber,strEntEmail,strEquipmentDate,strMaxYear,strFlowName,nFlowState 
from t_qyequipment 
where nEquipmentId not in
(select top 360 nEquipmentId from t_qyequipment Where nFlowState>100 and 1=1 order by nFlowState ASC ) and nFlowState>100
ORDER BY nFlowState ASC 

这是拼接好的SQL 
在分到17页之后后面的记录就会跟之前一页的记录相同
到底是什么问题?

------解决方案--------------------
select top 20 nEquipmentId,strEntName,strEquipmentType,strRegCode,strProduceCorp,strEquipmentModel,strEquipmentNumber,strEntEmail,strEquipmentDate,strMaxYear,strFlowName,nFlowState
from t_qyequipment
where nEquipmentId not in
(select top 380 nEquipmentId from t_qyequipment Where nFlowState>100 and 1=1 order by nFlowState ASC ) and nFlowState>100
ORDER BY nFlowState ASC

红色部分的排序字段用主键看看!
  相关解决方案