Developping for the translation industry RSS 2.0



 Tuesday, 09 February 2010

Here is a quick and easy way to remove multiple whitespaces from a string, leaving only one space character between tokens.

CREATE FUNCTION dbo.CleanString
               (@string VARCHAR
(50))
RETURNS VARCHAR
(50)
AS
  BEGIN
    SET @string = Ltrim
(Rtrim(@string))
    
    WHILE Charindex
('  ',@string) > 1
      SET @string = Replace
(@string,'  ',' ')
    
    RETURN @string
  END

 

Other Posts:

How to generate random numbers with a T-SQL query

How to insert a file in an image column in SQL Server 2005

How to track the growth of your SQL Server database

SQL Server indexing best practices and guidelines

How to remove leading zeros from the results of an SQL Query

Tuesday, 09 February 2010 13:24:17 (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Code Snippet | SQL
Comments are closed.

Navigation
Advertisement
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2018
Stanislas Biron
Sign In
Statistics
Total Posts: 135
This Year: 0
This Month: 0
This Week: 0
Comments: 1
All Content © 2018, Stanislas Biron