Introduction:
In this article I will explain what is the replace function in SQL Server and how to use Replace() function in SQL Server.
Output: 'Aspdotnet Suresh'
In above query we declared string as 'Dasari Suresh', and declared string to replace 'Dasari' string value with 'Aspdotnet'string value.
In this article I will explain what is the replace function in SQL Server and how to use Replace() function in SQL Server.
Description:
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
Replace('string1','string2','string3')
|
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:
EX1:
Declaration
of replace function will be like this
SELECT REPLACE(' Dasari Suresh', 'Dasari', 'Aspdotnet')
|
In above query we declared string as 'Dasari Suresh', and declared string to replace 'Dasari' string value with 'Aspdotnet'string value.
Ex2:
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
Output:
Replace
|
Aspdotnet Suresh
|
Suresh Aspdotnet
|
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. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.