首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

T-SQL 轮换多个空格

2012-09-05 
T-SQL替换多个空格DECLARE @Demo TABLE(OriginalString NVARCHAR(4000)) INSERT INTO @Demo (OriginalStri

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!.

热点排行