|
Hi all, I have a account number field that gets supplied to us from one of our partners. The problem is they've dumped (what i think) is carriage returns in this field as REPLACE(field, ' ', '') doesn't seem to be picking them up. How do i identify and remove carraige returns, tabs, line feeds, whitespace, any garbage that isn't text or numbers?
(comments are locked)
|
|
Carriage returns (char(13)) line feeds (char(10)) and tabs (char(9)) can be easily replaced but its the 'other garbage' that can be difficult to eradicate - you either have to know what it is up-front and deal with it, like above, or have a list of valid characters and try and trap for those... for example if only numbers where allowed thanks kev and what about one or more blank spaces?
Jul 09 '12 at 03:13 PM
jhowe
The replace you quoted in your question should remove blank spaces
Jul 09 '12 at 03:29 PM
Kev Riley ♦♦
this has worked perfectly.
Aug 08 '12 at 12:39 PM
jhowe
(comments are locked)
|
|
For whatever replacements and matching in case you can use CLR, the most siple thing is to use a CLR RegEx implementation. You can take a look on SQL Server Regular Expressions – Replacements for sample implementation. For your concrete needs you can use the
(comments are locked)
|
|
Just for fun, I thought of handling it by using the cteTally which would return a string with valid characters only i.e. [0-9] and [A-Z] ([a-z] are handled by using the UPPER function, but can be handled the same way as [A-Z]) It can be turned into an inline function to scale up.
(comments are locked)
|
|
We get what appears to be "unvalidated" data from some of our vendors. Our database is based on the requirements of MS-Dynamics which is much more restrictive. Sometimes we get strange characters in and I use the following script to identify the data. By the way, I wrote this for SQL-2K so there are probably better ways of doing this now.
(comments are locked)
|

