This is some code I wrote in a doomed attempt to deal with some long hex strings in some of our database objects.
The effort was doomed, but this code seems to work fine.
The strings I was working with were fixed 24-hex-digit strings, but you could probably make this variable length (so long as the values fit in numeric(38) values).
This was for Sql Server 2016, so I didn't have string_split() or string_agg(). (String_split doesn't take empty string or null for separator.)
Prolly shouldn't use max here, maybe varchar(240) or so?