what is Stuff function
MS SQL
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 22, 2015, 4:29 AM EDT
TUFF() can be used to stuff a string into another string. It inserts the string at a given position, and deletes the number of characters specified from the original string.
DECLARE @string1 VARCHAR(20) = 'Microsoft Server'
DECLARE @string2 VARCHAR(20) = 'SQL Server 2005'
SELECT @string1 + ' -> ' + STUFF(@string1, 11, 0, 'SQL ')
AS 'String 1',
@string2 + ' -> ' + STUFF(@string2, 15, 1, '8 R2')
AS 'String 2'
Result Set:
String 1 String 2
—————————————- ————————————-
Microsoft Server -> Microsoft SQL Server SQL Server 2005 -> SQL Server 2008 R2
(1 row(s) affected)
In the first string it inserts 'SQL ' at specified position – 11, the third argument 0 indicated the number of characters to be deleted before inserting the new string.
For second string, we have deleted one (1) character starting from position 15, which deletes '5', and then it inserts the new string at position 15 – '8 R2'.
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 22, 2015, 4:33 AM EDT