I am attempting to proper case the contents of a column that has various erroneous inputs. The code I used worked on everything except where the word is all caps.
I can't do "lower(initcap(field))" because it breaks some of the other corrections in the code. Is there a way to fix them all at once? The ones in yellow are wrong, as the code puts spaces between the letters.
-- Replace dashes and underscores with a space, then insert a space before all Capital Letters for multiple words that contain no spaces but have caps, then trim, then Capitalize the initial letter of all words that are still lower case in the first letter. Lastly, remove double spaces
select old_name,regexp_replace(initcap(trim(regexp_replace(replace(replace(old_name,'_',' '),'-',' '), '([A-Z])', ' \$1')) ) , '\\s+', ' ') as fixed_name from mytable


