All Forums Database
Epaphra 4 posts Joined 08/14
17 Apr 2015
replace 3rd and 9th position In a string

I have string (varchar) and I am looking to replace 3rd and 9th position of the string with ‘$’ and ‘#’, on Microsoft SQL Server STUFF function will perform string replacement. Do we have any equivalent functions on Teradata? I gave a try with oreplace,  but it is not handy to identify string postions and substring aslo not helpful.
Actual string value   = AAABXXCYY  
Expected string value =AA$BXXCY#

VandeBergB 182 posts Joined 09/06
17 Apr 2015

If it's always the third and ninth position in the string, use this...substring(columnname from 1 for 2)||'$'||substring (columnname from 4 for 5)||'#'.

Some drink from the fountain of knowledge, others just gargle.

yuvaevergreen 93 posts Joined 07/09
22 Apr 2015

REGEX_REPLACE can be used in TD 14 ,if your string is having limited length.But,it may not be suitable for longer fields. substr would be a good option.


You must sign in to leave a comment.