Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Trim Non-Alpha characters from string Expand / Collapse
Author
Message
Posted Monday, July 19, 2010 11:32 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Saturday, November 29, 2014 3:55 PM
Points: 3,244, Visits: 5,010
Comments posted to this topic are about the item Trim Non-Alpha characters from string

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sometimes, winning is not an issue but trying.

You can check my BLOG here

Post #955294
Posted Tuesday, July 20, 2010 7:47 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, February 4, 2011 7:20 AM
Points: 977, Visits: 1,499
Pretty cool.

Tom Garth
Vertical Solutions

"There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers
Post #955576
Posted Tuesday, July 20, 2010 8:12 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, October 17, 2014 9:46 AM
Points: 225, Visits: 990
Very nice. Just so happens I was bemoaning having to write a 'strip non-numeric characters' function today. You probably saved me an hour! :D

Kate The Great
If you don't have time to do it right the first time, where will you find time to do it again?
Post #955611
Posted Tuesday, July 20, 2010 8:22 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, October 17, 2014 9:46 AM
Points: 225, Visits: 990
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
If you don't have time to do it right the first time, where will you find time to do it again?
Post #955619
Posted Tuesday, July 20, 2010 9:36 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, November 10, 2014 7:28 AM
Points: 26, Visits: 263
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
Post #955700
Posted Thursday, January 27, 2011 9:12 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, October 6, 2014 2:55 PM
Points: 143, Visits: 363
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
Post #1054654
Posted Friday, July 11, 2014 5:30 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, November 24, 2014 11:41 AM
Points: 7, Visits: 110
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)
Post #1591573
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse