The
CHARINDEX
Function
The CHARINDEX function returns the position of the first occurrence of a substring within a string.
Syntax
CHARINDEX(substring, string[, start_pos])
This function returns the position of the first argument, substring, within the second argument,
string. You can optionally specify a third argument, start_pos, to tell the function the position from
which to start looking. If you don’t specify the third argument, the function starts looking from the
first character. If the substring is not found, the function returns 0. For example, the following code
returns the first position of a space in ‘Itzik Ben-Gan’, so it returns the output 6.
SELECT CHARINDEX(' ','Itzik Ben-Gan');
www.it-ebooks.info
68
Microsoft SQL Server 2012 T-SQL Fundamentals
Do'stlaringiz bilan baham: |