jeaney
asked on
SQL REPLACE for multiple characters
Hi
I want to remove multiple characters (that are not necessary sequential) in a string.
To remove the character 'a' from a string I use the following:
REPLACE(mystring, 'a', '')
But if I want to remove all 'a's 'b's and 'c's how do I do it?
The following does not work but displays the logic I need:
REPLACE(mystring, 'a' | 'b' | 'c', '')
Fast reponse greatly appreciated!
I want to remove multiple characters (that are not necessary sequential) in a string.
To remove the character 'a' from a string I use the following:
REPLACE(mystring, 'a', '')
But if I want to remove all 'a's 'b's and 'c's how do I do it?
The following does not work but displays the logic I need:
REPLACE(mystring, 'a' | 'b' | 'c', '')
Fast reponse greatly appreciated!
ASKER
Mmmmh, thanks chedgey. I did think about doing it this way but was hoping there was a better way :(
Do you think this is the only way it can be done?
Will hold out to see if anyone else has any other suggestions.
Do you think this is the only way it can be done?
Will hold out to see if anyone else has any other suggestions.
Try TRANSLATE:
Select translate('AaBbCcUYTUYTUYT ','~abc',' ~') From Dual;
TRANSLATE('A
------------
ABCUYTUYTUYT
Select translate('AaBbCcUYTUYTUYT
TRANSLATE('A
------------
ABCUYTUYTUYT
PS: Note the required '~' character (or any other you want).
ASKER
Thanks Mike but I'm being told that TRANSLATE is not a recognised function name. I'm using MSSQl
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Replace( Repalce( Replace( MyString,'a','' ),'b','' ),'c','' )
Regards
Chedgey