If you really love derived tables...
DECLARE @mytable TABLE (mynewstring varchar(100)) --replace @mytable with your table name INSERT INTO @mytable VALUES ('20171126-401-9-4496') ,('1-401-9-4496') ,('1-1-1-1') ,('---') SELECT dT4.FirstVal + SecondVal + ThirdVal + FourthVal [newval] FROM ( SELECT LEFT('00000000', len('00000000') - (dT3.[firstD] - 1)) + LEFT(mynewstring, [firstD]) [FirstVal] ,LEFT('0000', len('0000') - ([secondD] - [firstD] - 1)) + SUBSTRING(mynewstring, [firstD] + 1, [secondD] - [firstD]) [SecondVal] ,LEFT('00', len('00') - ([thirdD] - [secondD] - 1)) + SUBSTRING(mynewstring, [secondD] + 1, [thirdD] - [secondD]) [ThirdVal] ,LEFT('0000', len('0000') - (len(mynewstring) - [thirdD])) + SUBSTRING(mynewstring, [thirdD] + 1, len(mynewstring) - [thirdD]) [FourthVal] FROM ( SELECT dT2.* ,CHARINDEX('-', dT2.mynewstring, dT2.[secondD] + 1) [thirdD] FROM ( SELECT dT.* ,CHARINDEX('-', dT.mynewstring, dT.[firstD]+1) [secondD] FROM ( SELECT mynewstring ,CHARINDEX('-', mynewstring, 0) [firstD] FROM @mytable ) AS dT ) AS dT2 ) AS dT3 ) AS dT4
Would produce output:
newval 20171126-0401-09-4496 00000001-0401-09-4496 00000001-0001-01-0001 00000000-0000-00-0000
The algorithm grabs the position of the dashes, sequentially. It then does string concatenation with 0's for that position. Finally, the values are concatenated.