Saturday, January 5, 2013

SQL: Replace String

Sometimes we need to replace some word from SQL Database table fields. In order to do that you have to follow the below query syntax:

Syntax:
Update TableName
set ColumnName = replace(ColumnName, 'String to be Replaced', 'String to be replaced With');

Example:
I am giving an example for this:

Update Post
set PostDescription = replace (PostDescription , '&', 'and');

This will replace '&' with 'and' whereever it founds this in the given column.


Hope now you can easily do it.

No comments:

Post a Comment