select top 1 a.colname -1 as colname
from tablename a
where a.colname > 1
and not exists (
select 1 from tablename
where colname = a.colname -1
)
order by a.colname
declare @str varchar(10)
set @str='1,3'
select min(number) from master..spt_values where type='p' and number>0 and charindex(','+rtrim(number)+',',','+@str+',')<=0