存储过程中怎样选择记录范围

tony_zq 2000-07-26 03:30:00
我的表中主键有很多重复的记录,假设一个为x, 有1000条,我怎样写存储过程查其中的100至200条
...全文
111 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
huntout 2000-07-26
  • 打赏
  • 举报
回复
create proc selPartRecords
@myF1 int
as

decalre @n
set @n = 0

declare @f1 int
declare @f2 int

declare cur1 scroll cursor for select f1,f2 from table1 where f1 = @myF1
open cur1
select f1 = 0, f2 = 0 into #table1
fetch absolute 101 from cur1 into @f1, @f2
while (select @@fetch_status) = 0 and @n < 100
begin
insert #table1(f1, f2) values(@f1, @f2)
set @n = @n + 1
fetch next from cur1 into @f1, @f2
end
close cur1
deallocate cur1
delete #table1 where f1 = 0 and f2 = 0
select * from #table1
drop tabel #table1
go
tony_zq 2000-07-26
  • 打赏
  • 举报
回复
Thanks, 再请问临时表也就是在存储过程中用create table吗?
wwwunix 2000-07-26
  • 打赏
  • 举报
回复
呵呵...吓我一跳,用huntout的方法没错。
huntout 2000-07-26
  • 打赏
  • 举报
回复
若你非要用存儲過程,就只好用cursor,先移到第100條處,然後一條一條記錄的讀100次到一個臨時表中。在把臨時表select出來。
tony_zq 2000-07-26
  • 打赏
  • 举报
回复
Sorry! 不是主键,SQL SERVER7.0 !
wwwunix 2000-07-26
  • 打赏
  • 举报
回复
主键怎么可能重复?数据库中主键是强制唯一的。你用的是什么数据库?

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧