December 9, 2014 at 7:50 pm
We have an address table with a house_num field which is a nvarchar.
Most of house numbers are numbers like 1234, 0989
but some of them have a letter behind it like 678 B, 8909 F, even some like this 123/B
we would like to remove any non-numeric letter for this column.
Is there a way to do it?
Thanks
December 10, 2014 at 3:36 am
LEFT(@housenumber,PATINDEX('%[^0-9]%',@housenumber+' ')-1)
Far away is close at hand in the images of elsewhere.
Anon.
December 10, 2014 at 5:56 am
There have been some really good discussions on this very topic. See http://www.sqlservercentral.com/Forums/Topic1585850-391-1.aspx for several different approaches to the problem.
December 10, 2014 at 6:24 am
Easy enough to do as others have shown - but why turn a valid address into an invalid one?
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
December 10, 2014 at 9:45 am
Thanks all.
The reason is the original code using that column will convert that column to int.
We are writing completely new application to replace the old code.
But for now the quick solution is to remove those non-numeric letter, which in our case does not really matter.
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply