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: 312 | Points: 40
Answer:

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,' ','{}'),'}{',''),'{}',' ')


Output:-
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