October 13, 2008 at 3:30 am
Hi all,
I am trying to remove all non alpha numeric characters from a string value, is it possible to do this with a replace, i'm sure I've seen this before, something similar to
SELECT 'This '' is a sample',
REPLACE('This '' is a sample','[^A-Z]','')
but this does not remove the ' character. Am I going mad?
Thanks,
Jackal
October 13, 2008 at 3:36 am
Hello
GSquared demonstrates an excellent function for this here:
http://www.sqlservercentral.com/Forums/Topic470379-338-1.aspx
Cheers
ChrisM
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
October 13, 2008 at 3:41 am
Hi Chris,
Thanks for that, I've had a look at that. Is it not possible to do this using a replace then?
October 13, 2008 at 3:46 am
Yes it is - GSquared posted a tried-and-tested function using REPLACE in the same thread. Problem is, there are so many possible characters to look for.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
October 13, 2008 at 3:59 am
Sorry, I'm being a clown, I skimmed over the article to quickly.
I see now the usage of the replace, however this is done in a while loop.
I was wondering if it is possible to do with just one call of the replace,
something like;
SELECT 'This '' is a sample',
REPLACE('This '' is a sample','[^A-Z]','')
October 13, 2008 at 4:05 am
Jackal (10/13/2008)
Sorry, I'm being a clown, I skimmed over the article to quickly.I see now the usage of the replace, however this is done in a while loop.
I was wondering if it is possible to do with just one call of the replace,
something like;
SELECT 'This '' is a sample',
REPLACE('This '' is a sample','[^A-Z]','')
😀 Don't you just wish! The functions are pretty quick and they also encapsulate the process nicely, but if you don't want to use a function for this, then it's possible to achieve much the same thing by joining a tally table to your target table.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
October 13, 2008 at 4:07 am
No, your right it is a quick solution and meets my needs.
I'll stick with it, but I was just wondering if it was possible to do it with just a singular 'REPLACE' command.
Thanks a lot for your help.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply