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

Query to Replace part of string in sql server | Replace function example

May 15, 2012

In this article I will explain what is the replace function in SQL Server and how to use Replace() function in SQL Server.
In previous post I explained article substring function in SQL server. Now I will explain what is Replace () function in SQL server and how to use it in our applications. In one application I got requirement like replace particular part of the string with another value to achieve this functionality I realized it’s better to use Replace () function.

Replace() function

This function is used to replace the all the occurrences of specified string value with another string value. Generally Replace function will take 3 arguments and that declaration will be like this

In this function

1st Argument specifies the string value

2nd Argument specifies required string to be updated in complete string

3rd Argument specifies replace required string value in complete string

Examples of Replace() Function:


Declaration of replace function will be like this

SELECT REPLACE(' Dasari Suresh', 'Dasari', 'Aspdotnet')
Output: 'Aspdotnet Suresh'

In above query we declared string as 'Dasari Suresh', and declared string to replace 'Dasari' string value with 'Aspdotnet'string value.


Suppose if we want to use Replace() function in table then our function declaration will be like this

SELECT  REPLACE (ColumnName,CompareText,ReplaceText) as ' Replace' FROM TableName
Ex: SELECT REPLACE(UserName,'Dasari', 'Aspdotnet') as 'Replace' FROM UserInformation

Above query will replace UserName which contains 'Dasari' value with 'Aspdotnet' string value like this


Aspdotnet Suresh
Suresh Aspdotnet

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

Get the latest,, 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


Give your Valuable Comments

Other Related Posts

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