STUFF Function

STUFF Function

  
In this article I am trying to illustrate a vary useful function of SQL Server called STUFF.
STUFF Function
Stuff is a T-SQL Function used to delete a specified length of characters within a string and replace with another set of characters.
  
Syntax:
STUFF(Character_expression1, start, length, Character_expression2)
Character_expression1:
Represents the string in which the stuff function is to be applied.
Start:
It indicates the starting position of the character in the string of Character_expression1.
Length:
The length of the characters, which need to be replaced.
Charcter_expression2:
 It is the string that will be replaced to the start position.
Example:
SELECT STUFF(‘joydeep’, 2, 3, ‘xxxxx’)
—————
jxxxxxeep
Here “o” is the starting position 2, so from position 2 it takes 3 character “oyd” and replace it by “xxxxx”.
Posted by: MR. JOYDEEP DAS

Related Posts