读书人

MS SQL分页有关问题

发布时间: 2012-03-09 21:42:54 作者: rapoo

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

红色部分的排序字段用主键看看!

读书人网 >SQL Server

热点推荐