PradysTechBlog

Yet another blog

REPLACE in T-SQL

Replace () is used to replaces all occurrences of a specified string value with another string value.

Syntax

REPLACE ( string_expression , string_pattern , string_replacement )

Where string_expression is the string to be searched , string_pattern is the substring that needs to be searched and  string_replacement is the string which will replace the string_pattern

SELECT REPLACE(‘godisgreat’,’is’,’was’);
GO

The output would be godwasgreat. It searched for the string “is” within the string “godisgreat” and replaced the occurance of “is” with “was”.

SELECT REPLACE(‘godisgreatis’,’is’,’was’);
GO

The output would be godwasgreatwas.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: