how are you comparing? 15 minutes?
here, try sth. like this.
runs about 1 ms.
declare @nums varchar(100) = '1,2,3,4,5,6,8,10'
declare @id varchar(20), @start bigint = 0, @end bigint = 0, @rest varchar(max), @sep char(1) = ',';
declare @tabNums table (Num int primary key clustered not null)
while 1 = 1
begin
set @start = @end + 1;
set @end = charindex(@sep, @nums, @start)
if @end = 0
set @id = substring(@nums, @start, len(@nums) - @start + 1);
else
set @id = substring(@nums, @start, @end - @start);
insert
@tabNums
(Num)
values
(@id)
;
if @end = 0
break;
end
declare @num int, @num_before int = -1
declare curNumChain cursor
for
select
Num
from
@tabNums
order by
Num asc
open curNumChain ;
Fetch NEXT FROM curNumChain INTO @num
While (@@FETCH_STATUS <> -1)
begin
if @num is null
break;
if @num_before > -1
if (@num - @num_before) > 1
begin
set @num_before = @num_before + 1
while @num_before < @num
begin
select convert(varchar, @num_before) + ' is missing'
set @num_before = @num_before + 1
end
end
set @num_before = @num
Fetch NEXT FROM curNumChain INTO @num
end
close curNumChain
deallocate curNumChain