字段循环增加内容
我想给emBaseInf表中Mark字段为空的记录
修改为一个不唯一的值 0001到9999的值得
这个存储过程要怎么写呢?
[解决办法]
with a1 as
(
select mark,row_number() over (order by @@servername) re from emBaseInf where Mark=''
)
update a1 set mark=right('000'+rtrim(re),4)
[解决办法]
1楼正解我蹭分
[解决办法]
修改为一个不唯一的值,这样吗:
create table tb(ID int, mark varchar(100))
insert into tb
select 1,null union all
select 2,'a' union all
select 3,null union all
select 4,'b' union all
select 5,'b' union all
select 6,null
go
declare @t int
set @t = 0
update tb
set @t = @t + 1,
mark = case when mark is null then right('000'+cast(@t as varchar),4)
else mark end
select *
from tb
/*
IDmark
10001
2a
30003
4b
5b
60006
*/