Поскольку я не знаю вашу версию SQL Server, и вы еще не сказали, на каком языке вы хотите это, вот ответ на SQL Server 2017:
--Your Sample Data
WITH VTE AS(
SELECT V.SomeString
FROM (VALUES('000000000000000000000000000000'),
('168000000000000000000000000000'),
('192000164000000000000000000000')) V(SomeString)),
--The Solution
N AS(
SELECT N
FROM (VALUES(NULL),(NULL),(NULL),(NULL),(NULL),(NULL))N(N)),
Tally AS(
SELECT TOP 30 ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) I
FROM N N1, N N2),
NonZero AS(
SELECT V.SomeString,
T.I,
SS.C
FROM VTE V
CROSS JOIN Tally T
CROSS APPLY (VALUES(SUBSTRING(V.SomeString,T.I,1))) SS(C)
WHERE SS.C != '0')
SELECT V.SomeString,
LEFT(CONCAT(STRING_AGG(NZ.C,'') WITHIN GROUP (ORDER BY NZ.I),REPLICATE('0',30)),30) AS NewString
FROM VTE V
LEFT JOIN NonZero NZ ON V.SomeString = NZ.SomeString
GROUP BY V.SomeString;
дб <> скрипка