Usage of STUFF and SQLSTUFF in SQL
1. Role
Delete characters of the specified length and insert a group of characters at the specified start point.
2. Syntax
STUFF ( character_expression , start , length ,character_expression )
3. Example
The following example deletes the three characters starting from the first position (character B) in abcdef, and inserts the second string at the start of the deletion to create and return a string.
SELECT STUFF('abcdef', 2, 3, 'ijklmn')GO
The following is the result set.
Aijklmnef
4. Parameters
Character_expression
A character data expression. Character_expression can be a constant, variable, character column, or binary data column.
Start
An integer that specifies the start position of deletion and insertion. If start or length is negative, an empty string is returned. If start is longer than the first character_expression, an empty string is returned. Start can be of the bigint type.
Length
An integer that specifies the number of characters to delete. If the length is longer than the first character_expression, the last character in the last character_expression can be deleted at most. Length can be of the bigint type.
5. Return type
If character_expression is a supported character data type, character data is returned. If character_expression is a supported binary data type, binary data is returned.
6. Remarks
If the result value is greater than the maximum value supported by the return type, an error is returned.
The above section describes the usage of STUFF in SQL. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!