How could you remove all characters that are not alphabetic from a string?
What about non-alphanumeric?
Does this have to be a custom function or are there also more generalizable solutions?
How could you remove all characters that are not alphabetic from a string?
What about non-alphanumeric?
Does this have to be a custom function or are there also more generalizable solutions?
If you are like me and don't have access to just add functions to your production data but still want to perform this kind of filtering, here's a pure SQL solution using a PIVOT table to put the filtered pieces back together again.
N.B. I hardcoded the table up to 40 characters, you'll have to add more if you have longer strings to filter.
--First create one function
Now call this function like
Its result like
Believe it or not, in my system this ugly function performs better than G Mastros elegant one.
I put this in both places where PatIndex is called.
for the custom function above RemoveNonAlphaCharacters and renamed it RemoveNonAlphaNumericCharacters
I knew that SQL was bad at string manipulation, but I didn't think it would be this difficult. Here's a simple function to strip out all the numbers from a string. There would be better ways to do this, but this is a start.
Output
Round 2 - Data-Driven Blacklist
Output
My challenge to readers: Can you make this more efficient? What about using recursion?
From performance perspective I'd use Inline Function: