One of our customers had this problem where they add the Customer Service Manager’s address to all accounts they manage manually. When this guy leaves the company, someone has to use the UI and manually go through thousands of records one by one and remove the email id. The column which stores these email values in the table sometimes has multiple emails separated by a comma(,) and the specific email that needs to be removed could be at the beginning, end or any any other random place in the string. We wanted to create a stored procedure which accepts target email as parameter and deletes all occurrences. This whole thing appeared too complex until I figured out all it takes is an update command and use of TSQL function REPLACE.
Lets say we would like to remove joker@GothamCity.com. Who in his right mind would want to keep the Joker :). Lets have some test data to play around.
The actual stored procedure. Its self explanatory.