Friday, 18 November 2011

STUFF Example


STUFF ( character_expression , start , length ,character_expression )

The following example returns a character string created by deleting three characters from the first string, abcdef, starting at position 2, at b, and inserting the second string at the deletion point.

SELECT STUFF('abcdef', 2, 3, 'ijklmn');
GO
Result
aijklmnef

At first sight it might not be clear directly how to insert a character (or a string) instead of substituting characters in the original string.
To insert a string, without replacing/substituting characters in the original string you need to specify a length of 0 (zero).

SELECT STUFF('abcghi', 4, 0, 'DEF');

Result
abcDEFghi

No comments:

Post a Comment