Posted By

jprochazka on 12/21/12


Tagged

mssql


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Beppoi


SQL Server: Remove extra spaces from a string.


 / Published in: SQL
 

Removes extra spaces from a string in SQL Server.

  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   <

You need to login to post a comment.