You need just this:
SELECT @list = seg_tag
+ '01' + RIGHT('0' + CAST(LEN(ID_Type) AS varchar), 2)
+ ID_Type
+ '02' + RIGHT('0' + CAST(LEN(IDNumber) AS varchar), 2)
+ IDNumber
FROM #TEMP_TABLE_ID
Or
SELECT @list = seg_tag
+ '01'
+ CASE WHEN LEN(ID_Type) < 10 THEN '0' ELSE '' END +
+ CAST(LEN(ID_Type) AS varchar)
+ ID_Type
+ '02'
+ CASE WHEN LEN(IDNumber) < 10 THEN '0' ELSE '' END +
+ CAST(LEN(IDNumber) AS varchar)
+ IDNumber
FROM #TEMP_TABLE_ID
0
solved SQL Field Length