34,593
社区成员
发帖
与我相关
我的任务
分享
declare @t table(col varchar(15))
insert @t select '00-c0000-001'
insert @t select '00-c0000-002'
insert @t select '00-c0000-003'
insert @t select '00-c0000-005'
insert @t select '00-c0000-009'
insert @t select '00-c0000-100'
insert @t select '00-c0000-108'
insert @t select '00-c0000-110'
select top 1 left(col,len(col)-3)+right(right(col,3)+999,3) from @t a
where right(col,3) <> (select count(*) from @t b where col<=a.col)
order by col
/*
---------------------
00-c0000-004
(所影响的行数为 1 行)
*/
select top 1 convert(int,right(col,3))+1 from t a
where exists (select count(*) <> convert(int,right(a.col),3) from t b where col<=a.col)