日期:2014-05-17 浏览次数:20707 次
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
/*
ID mark
1 0001
2 a
3 0003
4 b
5 b
6 0006
*/