Pages

Tuesday 27 March 2012

SQL SERVER - STUFF() Function


The STUFF function inserts a given string into another string. This function deletes a specified length of characters from the first string at the start position and then inserts the second string into the first string at the start position.

General Syntax:
STUFF ( CharacterExpression , StartPos , length ,CharacterExpression )

Example:
SELECT STUFF('FunctionStuff()', 1, 8, 'ExampleOf')
GO

The result of this query is: 
-----------------------
ExampleOfStuff()

CharacterEexpression
It is an expression of character data.  CharacterEexpression can be a constant, variable, or column of either character or binary data.

StartPos  
Is an integer/bigint value that specifies the location to start deletion and insertion.

length  
Is an integer/bigint that specifies the number of characters to delete.

It returns character data if character_expression is one of the supported character data types. Returns binary data if character_expression is one of the supported binary data types.

The use of this function can be found to get Comma Separated Values

No comments:

Post a Comment