SQL Server 2012. Need to get numeric part with 6 figures, if not enough figures fill with leading zeros. Code is nvarchar type.
TABLE_A Before update
Id Code
1 s33404tft
2 dd345ui
3 456567t
4 8746
TABLE_A After Update
Id Code
1 033404
2 000345
3 456567
4 008746
sql script:
Update table_A
SET Code=FORMAT((SELECT SUBSTRING(code, PATINDEX('%[0-9]%', code), PATINDEX('%[0-9][^0-9]%', code + 't') - PATINDEX('%[0-9]%', code) + 1) AS Number
FROM Table_A),'000000')
It does not work.