How can we Replace Multiple Spaces in String with a Single Space in Sql Server?

 Posted by Vishalneeraj-24503 on 3/1/2015 | Category: Sql Server Interview questions | Views: 339 | Points: 40

We have to write below code:-
Select Replace(Replace(Replace(@str,' ','{}'),'}{',''),'{}',' ');

DECLARE @str varchar(150)
SET @str='Hello Welcome to dot net funda . com'
Select Replace(Replace(Replace(@str,' ','{}'),'}{',''),'{}',' ')

Hello Welcome to dot net funda . com

Alternatively,we can create a Function,which will return us a string and this function may be used in different places.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response