Remove multiple whitespace from a string (alternat

,

Here's an alternate way of removing multiple white spaces by using the REPLACE command.

CREATE  FUNCTION dbo.udfCleanString (@string VARCHAR(50))  
RETURNS VARCHAR(50)
AS
BEGIN 
	SET @string = LTRIM(RTRIM( @string ))

	WHILE CHARINDEX('  ', @string ) > 1
		SET @string = REPLACE(@string, '  ', ' ')

	RETURN @string
END

Rate

Share

Share

Rate