Sep 24, 2012

STUFF & REPLACE in SQL SERVER

STUFF

What STUFF does is, it inserts a string for the given expression of string. At a give start_position, it will start to delete the character mentioned on the length_to_delete and insert the replacement word.

STUFF(expression,start_position,length_to_delete,replace_with)

eg.

SELECT STUFF('Younten',5,3,'10')
SELECT STUFF('Younten',5,0,'10')

Output:
Youn10
Youn10ten

REPLACE

What REPLACE does is, it will replace every character in the given string.

REPLACE(expression,patter,replace_with)

eg.

SELECT REPLACE('Younten','Y','y')
SELECT REPLACE('Younten','n','N')

Output:
younten
YouNteN

No comments:

Post a Comment