Translate

What is REPLACE and STUFF functions in SQL Server?

STUFF function is used to replace part of a string with another string.

Syntax:

STUFF ([First String], [Position], [Length of the String], [Second String])

[First String] – The String that need to be overwritten.
[Position] - Starting Position of the String for overwriting.
[Length of the String] - Length of string to be replaced.
[Second String]- String that need to overwrite.

Example:
SELECT STUFF('Ajay', 2, 3,'nuj')

It will give Output: Anuj

REPLACE function is used to replace occurrences of a string by another string.

Syntax:
REPLACE([Main String], [String to replace], [String to replace with])

Example:
SELECT REPLACE('I am going', 'going', 'coming')

It will give Output: I am coming

No comments:

Post a Comment