问一下
Jackile(快呀,快来呀!) 发表的
--处理查询的 topicid
set @i=@currentpage*@pagesize
set rowcount @i
select topicid into #t from tb_club_topic
where boardID=12402 And deletemark=0
order by istop desc, LastDateTime desc
set @i=@i-@pagesize ****
set rowcount @i
delete from #t
有关键字的时候:
首先定义一个数num,num=n-m
SELECT TOP num *
FROM Balcony
WHERE (关键字 NOT IN
(SELECT TOP m 关键字
FROM Balcony))
如果没有关键字,就建立临时表,这我没试过!你可以照swand(钢板日穿)和ysm0_o(snoopy)说的试一下!
1 写个存储过程
2 给你一段代码参考下,邹建写的
create proc p_qry
@currentpage int,
@pagesize int=20 --默认每页20条记录
as
set nocount on
--查询处理
if @currentpage=1 --第一页就直接查询
begin
set rowcount @pagesize ******
select * from tb_club_topic
where boardID=12402 And deletemark=0
order by istop desc, LastDateTime desc
end
else
begin --如果查询的不是第一页
declare @i int
--处理查询的 topicid
set @i=@currentpage*@pagesize
set rowcount @i
select topicid into #t from tb_club_topic
where boardID=12402 And deletemark=0
order by istop desc, LastDateTime desc
set @i=@i-@pagesize
set rowcount @i
delete from #t
--返回查询结果
select * from tb_club_topic a
where exists(
select * from #t where topicid=a.topicid)
order by istop desc, LastDateTime desc
end
set rowcount 0
go
begin set nocount on
declare @p1 int
exec sp_cursoropen @p1 output,'select * from table ' --把你要查询的语句写到里面也可以排序
exec sp_cursorfetch @p1,16,开始行数,结束行数 --把你想要查出的行数范围写上
exec sp_cursorclose @p1
end
begin set nocount on
declare @p1 int
exec sp_cursoropen @p1 output,'select * from table ' --把你要查询的语句写到里面也可以排序
exec sp_cursorfetch @p1,16,1,10
exec sp_cursorclose @p1
end