notepad++ and regex for the rescue :
extract your procedure into plain text and put it in notepad++ then replace with some regex.
find:
(?i)CONVERT(.*?).*?)(?-i)
replace:
RTRIM($0)
and here is the example result:
convert(varchar(5), col$1) + '~' + CONVERT(varchar(8), col$2) + '~AD~'
after replace:
RTRIM(convert(varchar(5), col$1)) + '~' + RTRIM(CONVERT(varchar(8), col$2)) + '~AD~'
if every string start with CONVERT(
and end with )
this regex expression should work but be careful and check each one IMO. those should also take care of case sensitive and multiple match in one line.
if the string have more then two pairs of parentheses with in convert(...)
then this will still fail, in that case it will be better just manual adjust.
here is regex-101.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…