SQL SERVER: REPLACE FUNCTION

SQL SERVER: REPLACE FUNCTION

This SQL Server tutorial explains how to use the REPLACE function in SQL Server (Transact-SQL) with syntax and examples.

DESCRIPTION

The SQL Server (Transact-SQL) REPLACE function replaces a sequence of characters in a string with another set of characters, not case-sensitive.

SYNTAX

The syntax for the REPLACE function in SQL Server (Transact-SQL) is:
REPLACE( string1, string_to_replace, replacement_string )

Parameters or Arguments

string1
The source string from which a sequence of characters will be replaced by another set of characters.
string_to_replace
The string that will be searched for in string1.
replacement_string
The replacement string. All occurrences of string_to_replace will be replaced with replacement_string in string1.

APPLIES TO

The REPLACE function can be used in the following versions of SQL Server (Transact-SQL):
  • SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

EXAMPLE

Let's look at some SQL Server REPLACE function examples and explore how to use the REPLACE function in SQL Server (Transact-SQL).
For example:
SELECT REPLACE('mindSforest.com', 'S', '3');
Result: 'mind3fore3t.com'          (both s and S are replaced by 3)
SELECT REPLACE('MINDSforest.com', 'Minds', '1234');
Result: '1234forest.com'
SELECT REPLACE('mindsforest.com', 'i', '123');
Result: 'm123ndsforest.123om'
SELECT REPLACE('Minds Forest', ' ', 'B');
Result: 'MindsBForest'
Share on Google Plus

About Mindsforest

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment