在一个视图里面有三个字段是主键,请问如何实现分页!
解决方案 »
- 哪样的是大对象数据类型?
- SQL中,变量与字符串之间的连接
- 求SQL语法
- 如果数据库字段定义成unicode格式,是不是在win98系统上就无法正常显示呀?
- 为什么group by 后不是我希望的结果?
- 请问怎么把字符串转换成数据库SQL语句格式
- 表的列名能改吗?
- 为什么老是提示,字符串转换成datetime出错呢?我觉得是对的啊
- SQL Server 表中的大批数据如何导成XML文档?!!急!!先行谢过!
- 求助!!!
- 比较难的一条SQL语句
- SSPI handshake failed with error code 0x8009030c while establishing a connection with integrated security; the connection has be
比如每页20,找第5页,id1,id2,id3为联合主键:
1.用not exists
select top 20 * from tab A
where not exists (select 1 from (select top 80 * from tab order by id1,id2,id3) T where A.id1=T.id1 and A.id2=T.id2 and A.id3=T.id3)
order by id1,id2,id32.用left join
select top 20 A.* from tab A
left join (select top 80 * from tab order by id1,id2,id3) T
on A.id1=T.id1 and A.id2=T.id2 and A.id3=T.id3)
where T.id1 is null
order by A.id1,A.id2,A.id3
@sqlstr nvarchar(4000), --查询字符串
@pagecount int, --第N页
@pagesize int --每页行数
AS
BEGIN
set nocount on
declare @P1 int, --P1是游标的id
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1,@rowcount=@rowcount output
select @rowcount as 总行数,ceiling(1.0*@rowcount/@pagesize) as 页数,@pagecount as 当前页
set @pagecount=(@pagecount-1)*@pagesize+1
exec sp_cursorfetch @P1,16,@pagecount,@pagesize
exec sp_cursorclose @P1
endGO