
| home | AJAX (6) || C#.NET (5) || Coldfusion Development (16) || DHTML (14) || Flash Development (19) || jQuery (4) || MSSQL (2) || UNIX (10) |
| 4.11.08 | MSSQL Functions To Strip Non-AlphaNumeric and Non-Numeric Characters In Character Fields |
Thanks to Dan Venor and Scott Fitzpatrick and a little help isolating the ASCII Character values here are a two functions for use with inline MSSQL queries to strip non-alphanumeric and non-numeric characters in character fields respectively. This comes in handy if you’re using older versions of mssql that do not have regex (regular expression) syntax built in.
RemoveNonAlphaNumeric
Download this code: mssql_RemoveNonAlphaNumeric_fn.sql
RemoveNonNumeric
Download this code: mssql_RemoveNonNumeric_fn.sql
To use either, simply add as a function to the appropriate database which might involve bribing your DBA. Then use with inline SQL such as:
SELECT database.dbo.RemoveNonAlphaNumeric_fn('(555)444-1212')
or
SELECT database.dbo.RemoveNonAlphaNumeric_fn(CONVERT(VARCHAR(255), numericField)) FROM table WHERE table.index = 1
No comments