That stack overflow thing may be overkill if you just have a single string per table row. Perhaps this:;with yourTable (id, myString) as( select 1, 'basic56' union all select 2, 'BASIC6' union all select 3, 'baseid100' union all select 4, 'a;ljasd200010' union all select 5, '123dks')select id ,case when patindex('%[^0-9]%', reverse(myString))-1 < 1 then NULL else right(myString, patindex('%[^0-9]%', reverse(myString))-1) end digitsfrom yourTableOUTPUT:id digits----------- -------------1 562 63 1004 2000105 NULL
Be One with the OptimizerTG