microsoft:microsoft_sql_server:sql:format:convert_multiple_and_duplicate_spaces_to_single_space
This is an old revision of the document!
Microsoft - Microsoft SQL Server - SQL - Format - Convert Multiple and Duplicate Spaces to Single Space
Using a WHILE loop with REPLACE
SQL QUERY
DECLARE @TestString VARCHAR(200); SET @TestString=' Ex ample St ring '; WHILE CHARINDEX(' ',@TestString) <> 0 SET @TestString = REPLACE(@TestString,' ',' '); SELECT @TestString AS RESULT;
or
DECLARE @TestString VARCHAR(200); SET @TestString=' Ex ample St ring '; WHILE CHARINDEX(' ',@TestString) <> 0 SET @TestString = REPLACE(@TestString,' ',' '); SELECT LTRIM(RTRIM(@TestString)) AS RESULT;
microsoft/microsoft_sql_server/sql/format/convert_multiple_and_duplicate_spaces_to_single_space.1628172583.txt.gz · Last modified: 2021/08/05 14:09 by peter