[sql server] 问题总结6- 提取行号 ROW_NUMBER 分页

本文介绍了在SQL Server 2000和2005中使用ROW_NUMBER函数进行数据分页的方法,通过示例展示了如何根据特定条件对数据进行排序并分配行号,以实现分页查询。同时提供了一个分页存储过程的示例。
摘要由CSDN通过智能技术生成

 

在SQL 2000 和 2005下 的不同 方法

 

 

先说 2000下的

 

create table #temp1
(
ID int not null ,
code varchar(10) not null
primary key(ID,Code) 
)

insert into #temp1(ID,code) values(1,'01')
insert into #temp1(ID,code) values(3,'01')
insert into #temp1(ID,code) values(100,'01')
insert into #temp1(ID,code) values(5,'02')


--想得到的结果是里面的ID更新为按循序,1,2,3,4的 (ID里面具体那个是1,那个是2,无所谓的)
--要求:SQL2000下面,不能使用临时表或其它表哦
/*
1,01
2,01
3,02
4,01
*/

select * from #temp1

drop table #temp1
方法1:
declare @num int
set @num = 0
update #temp1 set ID = @num , @num = @num + 1
方法2:
select no = ( select count ( 1 <
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一直学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值