Here is the complete code which can achieve the required result
1) store the splitted string into a table @myvalues (I have written a solution to split a string into many rows using Recusrsivity in this Link )
2) Store the conditions in Table @tabcheck (length of each string)
3) Make a jointure between @myvalues and @tabcheck to get the result
declare @str as nvarchar(max)
set @str='116-500-325663-1';
declare @separator as char(1)
set @separator='-';
declare @tabcheck as table(id int,fromval int ,toval int)
insert into @tabcheck values(1,3,3),(2,1,3),(3,5,7),(4,1,2);
declare @myvalues as table(id int identity(1,1),myval varchar(100));
with cte as(
select @str [mystr],
cast(1 as int) [Start],
charindex(@separator,@str)as Nd
union all
select substring(@str,nd+1,len(@str)),cast(Nd+1 as int),charindex(@separator,@str,Nd+1) from cte
where nd>0
)
insert into @myvalues(myval)
select case when nd>0 then substring(@str,start,Nd-start)
else substring(@str,start,len(@str)) end [splitted]
from cte OPTION (MAXRECURSION 1000);
declare @result as int;
with mytab as(
select t1.id,t1.myval,len(t1.myval) L,t2.fromval,t2.toval,
case when len(t1.myval)>=t2.fromval and len(t1.myval)<=t2.toval then 1 else 0 end [result]
from @myvalues t1 inner join @tabcheck t2 on t1.id=t2.id)
select @result=count(1) from mytab where result=0 ;
select case @result when 0 then 'OK' else 'Mistake' end [result]