Below is the function:
         create function dbo.CleanTheStringAdv (@theString as nvarchar(500), @CleanMode as nvarchar(500))  returns nvarchar(500)   AS begin   --define variables declare @strAlphaNumeric nvarchar(500)   declare @i int declare @strChar nvarchar(500) declare @CleanedString nvarchar(500) --initiate values set @CleanedString =''   set @theString = @theString + '' SET @i = 1 --Determine if we are looking for numeric values only or numbers and letters SET @strAlphaNumeric = case @CleanMode --case @CleanMode WHEN '1' THEN  '0123456789' WHEN '2' Go to the complete details ...