Create Table #Tmp
([SINFO] [nvarchar](50) NULL)
declare @ddd int =74000
WHILE @ddd < 74015
BEGIN
select @ddd= @ddd +1
insert into #Tmp (SINFO) values ( 'G' + Convert(Nvarchar , @ddd ))
END;
--all gaps
select #Tmp.SINFO , Table_2.SINFO from #Tmp
left join Table_2 on #Tmp.SINFO = Table_2.SINFO
where Table_2.SINFO is null
order by #Tmp.SINFO
--Frist gaps
select top(1) #Tmp.SINFO , Table_2.SINFO from #Tmp
left join Table_2 on #Tmp.SINFO = Table_2.SINFO
where Table_2.SINFO is null
order by #Tmp.SINFO
If(OBJECT_ID('tempdb..#Tmp') Is Not Null)
Begin
Drop Table #Tmp
End
1条答案
按热度按时间ckx4rj1h1#
创建一个包含所有数字的临时表,然后左键联接基表并选择所有的空值或顶值,例如