Remove all spaces from a string in SQL Server

后端 未结 23 899
死守一世寂寞
死守一世寂寞 2020-11-28 01:42

What is the best way to remove all spaces from a string in SQL Server 2008?

LTRIM(RTRIM(\' a b \')) would remove all spaces at the right and left of th

23条回答
  •  野性不改
    2020-11-28 02:04

    this is useful for me:

    CREATE FUNCTION dbo.TRIM(@String VARCHAR(MAX))
    RETURNS VARCHAR(MAX)
    BEGIN
        RETURN LTRIM(RTRIM(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@String,CHAR(10),'[]'),CHAR(13),'[]'),char(9),'[]'),CHAR(32),'[]'),'][',''),'[]',CHAR(32))));
    END
    GO
    

    .

提交回复
热议问题