declare @tableName varchar(50)
declare @pageIndex int
declare @pageSize int
set @pageIndex = 3
set @pageSize = 20
declare @tempTable table
(
ID int Identity,
ajid varchar(50)
)
declare @maxCount int
set @maxCount = @pageIndex + @pageSize -1
--set ROWCOUNT @maxCount
insert into @tempTable
SELECT id FROM AJ_AQJDSB
order by id
select aj.* from @tempTable t
inner join @tableName t2
on t2.id=t.ajid
where t.id between @pageIndex and @maxCount