当前位置: 代码迷 >> SQL >> T-SQL 轮换多个空格
  详细解决方案

T-SQL 轮换多个空格

热度:15   发布时间:2016-05-05 13:37:13.0
T-SQL 替换多个空格
DECLARE @Demo TABLE(OriginalString NVARCHAR(4000)) INSERT INTO @Demo (OriginalString) SELECT ' I am     Incognito,   What    just    for   a  test!' UNION ALL SELECT '看看                     效果                     吧!' UNION ALL SELECT '也许     大概?!  可能' UNION ALL SELECT '我  不知道啊。 谢谢  !' UNION ALL SELECT 'English    is  Okey!.'--===== Reduce each group of multiple spaces to a single space     -- for a whole table without functions, loops, or other     -- forms of slow RBAR.  In the following example, CHAR(7)     -- is the "unlikely" character that "X" was used for in      -- the explanation. SELECT REPLACE(            REPLACE(                REPLACE(                    LTRIM(RTRIM(OriginalString))                ,'  ',' '+CHAR(7))  --Changes 2 spaces to the OX model            ,CHAR(7)+' ','')        --Changes the XO model to nothing        ,CHAR(7),'') AS CleanString --Changes the remaining X's to nothing   FROM @Demo  WHERE CHARINDEX('  ',OriginalString) > 0

I am Incognito, What just for a test!
看看 效果 吧!
也许 大概?! 可能
我 不知道啊。 谢谢 !
English is Okey!.
  相关解决方案