Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Introduction:

Here I will explain how to replace multiple spaces in string with single space in
sql server or sql server replace multiple spaces with one space in string or sql server remove extra multiple spaces from string without using any while loop.
Description:
In previous articles I explained replace function example in sql server, Query to remove first and last character from string in sql server, remove html tags from string in sql, substring function in SQL server and many articles relating to SQL server. Now I will explain how to replace multiple spaces in string with single space in sql server.

To replace multiple spaces in string with single space in sql server we need to write the query like this


Select REPLACE(REPLACE(REPLACE(@str,' ','{}'),'}{',''),'{}',' ')
Example


DECLARE @str varchar(150)
SET @str='Hello    Welcome   to   Aspdotnet-suresh.com'
Select REPLACE(REPLACE(REPLACE(@str,' ','{}'),'}{',''),'{}',' ')
Once we run above query we will get output like as shown below

Output:



If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

4 comments :

Anonymous said...

good!!!!!!!!!!

Anonymous said...

Very Useful

Anonymous said...

Very Helpfull thanks

Maneesh Deepankar said...

Great Help for Developers

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.