I am trying to remove certain characters in a string without removing them from peoples names.
I have tried using nested REPLACE statements, adding multiple CASE WHEN...THEN...ELSE statements but I am struggling to cover all bases with the code
In my table I have peoples names with prefixes and suffixes used to denote the status of the person in a number of instances.
This is an example of data in the table
ZZScott Buzzton SC
I need to remove the "ZZ" and "SC" text from here and just leave Scott Buzzton.
With the CASE statements I have been unable to get something that covers everything without layers of nesting
CASE
WHEN LEFT ( 'text' , 2 ) = 'ZZ' THEN STUFF ( 'text' , 1 , 2 , '' )
WHEN RIGHT ( 'text' , 2 ) = 'SC' THEN STUFF ( 'text' , LEN ( 'text' ) - 2 ) , 2 , '' )
ELSE 'text'
END
This only removes either "ZZ" or "SC" but not both. I was wondering if there was something simple I could do to remove them that doesn't involve altering the data in the table as that could break a number of reports and possibly our application
ADDITION: "ZZ" and "SC" are just 2 examples, there could be other texts used to denote status