62,041
社区成员
发帖
与我相关
我的任务
分享
declare @t table(b int,c varchar(30))
insert @t select 101,null
insert @t select 202,null
insert @t select 203,null
insert @t select 500,null
select * from @t
update a
set c=right(convert(char(8),getdate(),112),5)+right('00'+cast((select count(*)+1 from @t where b<a.b) as varchar(20)),2)
from @t a
select * from @t
/*
b c
----------- ------------------------------
101 NULL
202 NULL
203 NULL
500 NULL
(所影响的行数为 4 行)
(所影响的行数为 4 行)
b c
----------- ------------------------------
101 9063001
202 9063002
203 9063003
500 9063004
(所影响的行数为 4 行)
*/