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

charindex()

The string function charindex() returns an integer value which forms the starting position of an expression . The function charindex() will look for the value of the parameter "expression2" within the parameter "expression1" and returns the first position found as a number. If no values can be found "0" will be returned.

Syntax of the string function charindex()

    charindex([expression1, expression2])
    

The parameters of the string function charindex()

expression1 and expression2
The parameters "expression1" and "expression1" can be column names, constants, variables or expressions. They can be any of these datatypes: char, varchar, nchar, nvarchar, unichar, univarchar, binary or varbinary. . Wildcards within the parameter "expression1" are treated as normal characters. If the parameter "expression2" contains a NULL-value the number "0" is returned. If one of the parameters is a varchar and the other parameter a unichar datatype, the varchar value will be automatically converted into a unichar datatype, using implicit convertion. During this conversion, it can happen that the varchar value is cut off at the end.

Example for the string function charindex()

    select charindex("5", "1615234")
go
-----
4

Returns "4".

    select charindex("n", "information")
go
-----
2

Returns "2".

    select charindex("search_string", column_name)
  from table_name
go
-----
42

Returns 42, because the "search_string" in column "column_name" in the table "table_name" was the first to be found.

See also:

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