The following custom function provides a fix to this annoying "bug".
CREATE FUNCTION TrimAll (@s VARCHAR(MAX)) RETURNS VARCHAR(MAX) AS BEGIN RETURN RTrim(LTrim(Replace(Replace(Replace(Replace(@s, Char(160), ' '), Char(10), ''), Char(13), ''), Char(9), ''))) END GO
To use, simply do something like this
SELECT dbo.TrimAll(MyField) FROM MyTable
Use below if want to replace tabs as well.
ReplyDeleteCREATE FUNCTION TrimAll (@s VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
RETURN RTrim(LTrim(Replace(Replace(badword, Char(160), ' '), Char(9), '')))
END
GO