STUFF Function and its differences

Posted by Saranya Boopathi under Sql Server on 6/11/2013 | Points: 10 | Views : 874 | Status : [Member] | Replies : 2
What is the STUFF Function and How Does it Differ from the REPLACE Function?

Saranya Boopathi


Responses

Posted by: Niladri.Biswas on: 6/11/2013 [Member] Platinum | Points: 25

Up
0
Down
REPLACE is used to replace all the occurances of the given pattern in a string.

Example: select Replace('Niladri','N','M')

O/P: Miladri

STUFF: This function is used to replace the part of string with some other string.

syntax: STUFF (stringexpression, start, length, replacementcharacters)

Example:SELECT STUFF('My blogs are useful',4,5,'articles')

Output: My articles are useful

In this case , it replaces blogs (which appeared at position 4) with articles

Best Regards,
Niladri Biswas

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 6/11/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Saranya,
STUFF is used to replace the part of string with some other string.
Syntax:
STUFF (stringexpression, start, length, replacementcharacters)
Example:
SELECT STUFF('Aswini Blog is USEFUL',7,8,'DATABASE')
Output:
Aswini DATABASE is USEFUL

REPLACE is used to replace all the occurances of the given pattern in a string.
Syntax:
REPLACE ( string_expression , string_pattern , string_replacement )
Example:
select Replace('Aswini','W','S")
Output: Assini

I hope it will help you
Mark as answer if it helps you
Thanks&Regards





Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Saranya Boopathi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response