如果你仔細想想較小一套特殊的字符替換/刪除,你可以在你SELECT
使用嵌套REPLACE()
:
-- preparation of the example
CREATE TABLE #tt (id int identity (1,1), col text)
GO
INSERT INTO #tt (col) VALUES (N'this is a text
multiline
3rd line')
GO
-- run of the example
SELECT REPLACE(REPLACE(REPLACE(CAST(col as varchar(MAX)) ,
CHAR(9), '<9>'), -- replace '<9>' for '' to achieve removal
CHAR(10), '<10>'),
CHAR(13), '<13>') AS NewText
FROM #tt
--cleanup
--DROP TABLE #tt
輸出:
(1 row(s) affected)
NewText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
this is a text<13><10>multiline<13><10>3rd line
(1 row(s) affected)