34,590
社区成员
发帖
与我相关
我的任务
分享
declare @tb table (col varchar(60))
insert @tb select '京咨[2008]第17984号'
insert @tb select '京咨[2008]第18075号'
insert @tb select '京咨[2008]第18129号'
insert @tb select '京咨[2008]第18130号'
insert @tb select '京咨[2008]第18131号'
select left(col,charindex('第',col))+cast(ROW_NUMBER() OVER (order by col) as varchar(10))+'号'
from @tb
select id=identity(int,1,1),* into # from @tb
select left(col,charindex('第',col))+cast(id as varchar(10))+'号' from #
create table tb(col varchar(60))
insert tb select '京咨[2008]第17984号'
insert tb select '京咨[2008]第18075号'
insert tb select '京咨[2008]第18129号'
insert tb select '京咨[2008]第18130号'
insert tb select '京咨[2008]第18131号'
update tb
set col=left(col,charindex('第',col))+rtrim((select count(1) from tb t where col<=tb.col))+'号'
select * from tb
/*
col
------------------------------------------------------------
京咨[2008]第1号
京咨[2008]第2号
京咨[2008]第3号
京咨[2008]第4号
京咨[2008]第5号
(5 row(s) affected)
*/
drop table tb
create table tb(col varchar(60))
insert tb select '京咨[2008]第17984号'
insert tb select '京咨[2008]第18075号'
insert tb select '京咨[2008]第18129号'
insert tb select '京咨[2008]第18130号'
insert tb select '京咨[2008]第18131号'
update tb set col='京咨[2008]第'+convert(varchar(10),id)+'号' from
(
select col,id=(select count(1) from tb where col<=a.col) from tb a
)b where tb.col=b.col
select finlno=replace(finlno,value,ltrim(cou))
from
(select
finlno,
value=replace(right(finlno,len(finlno)-charindex('第',finlno)),'号',''),
cou=(select count(1) from [Table] where finlno<=a.finlno) from [Table] a
)aa
create table tb(col varchar(60))
insert tb select '京咨[2008]第17984号'
insert tb select '京咨[2008]第18075号'
insert tb select '京咨[2008]第18129号'
insert tb select '京咨[2008]第18130号'
insert tb select '京咨[2008]第18131号'
select left(col,charindex('第',col))+cast((select count(1) from tb where col<a.col)+1 as varchar)+right(col,1)
from tb a
drop table tb
/*
--------------------------------------------------------------------------------------------
京咨[2008]第1号
京咨[2008]第2号
京咨[2008]第3号
京咨[2008]第4号
京咨[2008]第5号
(所影响的行数为 5 行)
*/
create table tb(col varchar(60))
insert tb select '京咨[2008]第17984号'
insert tb select '京咨[2008]第18075号'
insert tb select '京咨[2008]第18129号'
insert tb select '京咨[2008]第18130号'
insert tb select '京咨[2008]第18131号'
declare @c int
set @c=0
update tb set @c=@c+1,
col=left(col,charindex('第',col))+cast(@c as varchar)+right(col,1)
select * from tb
drop table tb
/*
col
------------------------------------------------------------
京咨[2008]第1号
京咨[2008]第2号
京咨[2008]第3号
京咨[2008]第4号
京咨[2008]第5号
(所影响的行数为 5 行)
*/