在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
(
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
set @num = 0
update #temp1 set ID = @num , @num = @num + 1
方法2:
select
no
=
(
select
count
(
1 <