Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL trim &nbsp (and other non-alphanumeric characters)

Tags:

We have some input data that sometimes appears with &nbsp characters on the end.

The data comes in from the source system as varchar() and our attempts to cast as decimal fail b/c of these characters.

Ltrim and Rtrim don't remove the characters, so we're forced to do something like:

UPDATE myTable
SET myColumn = replace(myColumn,char(160),'')
WHERE charindex(char(160),myColumn) > 0

This works for the &nbsp, but is there a good way to do this for any non-alphanumeric (or in this case numeric) characters?