一般製表符,換行符,回車是罪魁禍首,但如果遇到無法再去除空白字符,你可以創建這樣一個功能:
CREATE FUNCTION [dbo].[fn_Trim]
(
@str as varchar(1000)
)
RETURNS varchar(1000)
AS
BEGIN
--Replace all whitespace characers with Characer 32 whitespace
--NULL
Set @str = Replace(@str,CHAR(0),CHAR(32));
--Horizontal Tab
Set @str = Replace(@str,CHAR(9),CHAR(32));
--Line Feed
Set @str = Replace(@str,CHAR(10),CHAR(32));
--Vertical Tab
Set @str = Replace(@str,CHAR(11),CHAR(32));
--Form Feed
Set @str = Replace(@str,CHAR(12),CHAR(32));
--Carriage Return
Set @str = Replace(@str,CHAR(13),CHAR(32));
--Column Break
Set @str = Replace(@str,CHAR(14),CHAR(32));
--Non-breaking space
Set @str = Replace(@str,CHAR(160),CHAR(32));
Set @str = LTRIM(RTRIM(@str));
Return @str
END
GO
,然後用它來更新列爲:
Update Table_Names
set Name_ID = dbo.fn_Trim(Name_ID)
好點。嘗試過的字符(9),字符(10)和字符(13),但同樣的結果不斷髮生..是否有另一種選擇? – HelpASisterOut