SQL Server: Remove extra spaces from a string.


/ Published in: SQL
Save to your folder(s)

Removes extra spaces from a string in SQL Server.


Copy this code and paste it in your HTML
  1. CREATE FUNCTION [dbo].[RemoveSpaces] (@Str VARCHAR(MAX))
  2. RETURNS VARCHAR(MAX)
  3. AS
  4. BEGIN
  5. SET @str = REPLACE(@str,' ','{}')
  6. SET @str = REPLACE(@str,'}{','')
  7. SET @str = REPLACE(@str,'{}',' ')
  8. RETURN @str
  9. END

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.