|
patindex()
The
string function
patindex()
returns the starting position of the search pattern specified in the parameter "%pattern%" within the character string "char_expression".
Syntax of the String Function patindex()
patindex ( "%pattern%", char_expression | uchar_expression [, using
{bytes | characters | chars} ] )
The parameters of the String Function patindex()
"%pattern%"
The parameter "%pattern%" is a so-called
"character expression"
and must be declared as one of the
datatypes
char
or
varchar.
In addition, it can contain all
wildcards
permitted in
ASE®.
The wildcard "%" must be set before and after the search pattern, unless searching for start or end signs.
"char_expression"
The parameter "char_expression" can consist of a
column name, a
variable
or a
constant
and must be of one of the datatypes
char,
varchar,
nchar
or
nvarchar.
"uchar_expression"
The parameter "uchar_expression" can be a
column name, a variable or a constant and must be declared in on of the datatypes
unichar
or
univarchar.
"using"
The parameter "using" declares the format used for displaying the result. Allowed values are
"bytes", "characters" or "chars".
Example for the String Function patindex()
select patindex("%s%", "sybase")
go
-----
1
Returns "1".
select patindex("%s%", "Sybase")
go
-----
5
Returns "5".
select name from master..sysobjects
where patindex("sys*tes", name) > 0
go
-----
sysalternates
sysattributes
syscertificates
Returns all
objects
from the
system table
sysobjects
, starting with "sys" and ending on "tes".
select name from master..sysobjects
where patindex("%ter%", name) > 0
go
-----
monTableParameters
sp_dbcc_run_alterws
sysalternates
Returns all objects from the system table sysobjects containing the string "ter".
See also:
ASE T-SQL - Aggregate Functions, ascii(), char(), char(n), charindex(), char_length(), compare(), difference(), lower(), ltrim(), replicate(), reverse(), right(), rtrim(), sortkey(), soundex(), space(), str(), String Functions, stuff(), substring(), to_unichar(), uhighsurr(), ulowsurr(), upper(), uscalar().
|