July 19, 2010 at 11:32 pm
Comments posted to this topic are about the item Trim Non-Alpha characters from string
July 20, 2010 at 7:47 am
July 20, 2010 at 8:12 am
Very nice. Just so happens I was bemoaning having to write a 'strip non-numeric characters' function today. You probably saved me an hour! 😀
😎 Kate The Great :w00t:
If you don't have time to do it right the first time, where will you find time to do it again?
July 20, 2010 at 8:22 am
I did get an error applying to a nullable column. (LEN=0; Error was "TOP clause contains an invalid value.") Because I'm in a hurry I just threw a case statement around the function call but a clause in the function to work around that would be a nice enhancement.
😎 Kate The Great :w00t:
If you don't have time to do it right the first time, where will you find time to do it again?
July 20, 2010 at 9:36 am
Thank you for this example.
If you do much data cleansing or string manipulation, keep in mind that you can implement regular expression functionality in SQL Server 2005 and above. It's easier than I thought it would be, assuming your DBA allows you to enable CLR integration.
This article lays it out very well:
http://justgeeks.blogspot.com/2008/08/adding-regular-expressions-regex-to-sql.html
January 27, 2011 at 9:12 am
Thanks for the script, I like they way you created the tally table on the fly lilke that, I never thought of doing that! Here is what I've been using to do the same thing, it's pretty easy to modify to include/exclude numerics, spaces, certain special characters etc... which is why I like it.
DECLARE @data VARCHAR(100)
SET @data = '!2131231Atif123123 234234Sheikh6546'
WHILE PATINDEX('%[^a-z ]%', @data) > 0
SET @data = STUFF(@data, PATINDEX('%[^a-z ]%', @data), 1, '')
SELECT
RTRIM(LTRIM(@data)) AS Data
Thanks again!
Adam Sottosanti
July 11, 2014 at 5:30 am
works only partially - does not take in consideration that fact that some countries do have Accented alphas so the code as is removes them.
Select dbo.fnTrimNonAlphaCharacters('âáÉéôô') will just return an empty string for example.
one possible change to the code to allow for the above is
WHERE N <= LEN(@pString)
And (Ascii(SUBSTRING(@pString collate SQL_Latin1_General_CP1253_CI_AI,N,1)) between 97 and 122
Or Ascii(SUBSTRING(@pString collate SQL_Latin1_General_CP1253_CI_AI,N,1)) between 65 and 90
Or Ascii(SUBSTRING(@pString collate SQL_Latin1_General_CP1253_CI_AI,N,1)) = 32)
May 18, 2016 at 1:12 pm
Thanks for the script.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply