34,588
社区成员
发帖
与我相关
我的任务
分享
set @strSql='select cc.*,tbPortAutoComplte.PortName_chs from (select top 100 UserID,Name,CnName,SOG,InPort from VWShipInfo where ShipType=1 and (DATEDIFF(s, ReceiveTime, GETDATE()) <= 12*60*60) ) as cc LEFT OUTER JOIN dbo.tbPortAutoComplte ON cc.InPort = dbo.tbPortAutoComplte.ID ';
with t(c1,c2) as
(
EXEC Sp_executesql @strsql
)
select top @pagesize * from t where c1 not int(select top (@startRecordIndex-1) c1 from t order by c1)order by c1
declare @startRecordIndex int,
@pagesize int
set @startRecordIndex=20
set @pagesize=10
set @strSql='select top('+@pagesize+')cc.*,tbPortAutoComplte.PortName_chs from (select top 100 UserID,Name,CnName,SOG,InPort from VWShipInfo where ShipType=1 and (DATEDIFF(s, ReceiveTime, GETDATE()) <= 12*60*60) ) as cc LEFT OUTER JOIN dbo.tbPortAutoComplte ON cc.InPort = dbo.tbPortAutoComplte.ID where dbo.tbPortAutoComplte.ID>'+@startRecordIndex
EXEC Sp_executesql @strsql
set @strSql='select top('+ @pagesize+') cc.*,tbPortAutoComplte.PortName_chs from (select top 100 UserID,Name,CnName,SOG,InPort from VWShipInfo where ShipType=1 and (DATEDIFF(s, ReceiveTime, GETDATE()) <= 12*60*60) ) as cc LEFT OUTER JOIN dbo.tbPortAutoComplte ON cc.InPort = dbo.tbPortAutoComplte.ID where dbo.tbPortAutoComplte.ID>'+@startRecordIndex
EXEC Sp_executesql @strsql