select *,
case when RIGHT(a,5)%10000=0 then 2
when RIGHT(a,4)%1111=0 and RIGHT(a,4)>1000 then 2
when (RIGHT(a,4)-1234)%1111=0 and RIGHT(a,4)>1000 then 2
when RIGHT(a,3)%111=0 then 1
when (RIGHT(a,3)-123)%111=0 then 1
when right(a,3)='012' then 1
else 0
end
from tb