A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z  special characters  sybase-tech-blog


Category: ASE: Functions: String Functions

stuff()

The string function stuff() replaces a given number of characters in a string.

Syntax of the String Function stuff()

    stuff ( char_expression1 | uchar_expression1,
  start,
  length,
  char_expression2 | uchar_expression2 )

The parameters of the String Function stuff()

"char_expression1" and "char_expression2"
Replaces a given number of characters specified in the parameter "char_expression1" with a number of characters specified in parameter "char_expression2". Both parameters must be set either in single or double quotes. They can be variables or constants and must be of one of the datatypes char, varchar, nchar or nvarchar. If the value of the parameter "expression1" is NULL value, the NULL will also be returned. If unichar and varchar values are mixed in the two parameters "expression1" and "expression2", the varchar value will be automatically converted into a unichar value using implicit conversion. It is possible that characters are ommited during this operation.

"uchar_expression1" and "uchar_expression2"
A specified number of characters defined in the value of parameter "uchar_expression1" is substituted by the value specified in "uchar_expression2". Both parameters must be set in single or double quotes. They can be variables or constants and must be of one of the datatypes unichar or univarchar. If the value of parameter "expression1" is not a NULL value but parameter "expression2" is NULL, the return value will also be NULL.

"start"
The parameter "start" specifies the position of first character to be replaced. A negative value for parameter "start" returns a NULL value. The return value is also NULL, if the starting position is longer than "expression1".

"length"
The parameter "length" specifies the number of characters to be replaced. If the value of the parameter "length" is longer than "expression1", everything to the end of the string ("expression1") will be replaced by the value specified in parameter "expression2".

Example for the String Function stuff()

    select stuff("abcde", 2, 3, "234")
go
------
a234e

Replaces the characters "bcd" in the string "abcde" with "234".

    select stuff("abcde", 2, 3, "")
go
------
a e

Replaces the characters "bcd" in the string "abcde" with blanks.

    select stuff("abcde", 2, 6, "1234")
go
------
a1234

Replaces everything after the second character with "1234".

See also:

ASE T-SQL - Aggregate Functions,
ascii(),
char(),
char(n),
charindex(),
char_length(),
compare(),
difference(),
lower(),
ltrim(),
patindex(),
replicate(),
reverse(),
right(),
rtrim(),
sortkey(),
soundex(),
space(),
str(),
String Functions,
substring(),
to_unichar(),
uhighsurr(),
ulowsurr(),
upper(),
uscalar().