Does your database column contain multiple occurrances of these 'reserved words'? If so, you will also need some recursion. I wrote a function some time in the past to do this (back in our SQL 2000 days):/****** Object: UserDefinedFunction [dbo].[StripPattern] Script Date: 11/27/2007 13:14:17 ******//*This procedure takes in a pattern match parameter (see syntax for PATINDEX)and remove any characters that do not adhere to that pattern.*/CREATE FUNCTION [dbo].[StripPattern]( @Input VARCHAR(8000), @Pattern VARCHAR(100))RETURNS VARCHAR(8000)ASBEGIN WHILE PATINDEX(@Pattern, @Input) != 0 BEGIN SET @Input = REPLACE(@Input, SUBSTRING(@Input, PATINDEX(@Pattern, @Input), 1), '') END RETURN @InputEND
This utilized the pattern matching functionality of the PATINDEX function and can easily be enhanced to accept another input parameter to represent the replacement string (I hardcoded '' since the intent was to strip out bad data).