As a yard farmer, in development you may occasionally encounter to determine whether a character or character channeling is included in a text, in this article we will discuss using the CHARINDEX and PATINDEX functions to search for text columns and strings. The following will show you how these two functions work, explaining their differences.
CHARINDEX and PATINDEX functions are often used to search for characters or strings in a word. If the character being searched contains a character to search for, the two functions return a nonzero integer, which is the beginning of the character to be searched in the character being searched. The PATINDEX function supports searching using wildcards, while CHARINDEX does not support wildcard characters.
CHARINDEX function: Returns the starting position of a character or string within another string.
<font size= "3" >charindex (expression1, expression2 [, start_location]) </font>
Description:Expression1 is the character to be searched for in expression2, start_location is the position where CHARINDEX function begins to find expression2 in expression1.
CHARINDEX The function returns an integer that is the position of the string to be found in the string being searched for. If CHARINDEX does not find the string to find, then the function integer "0". Let's take a look at the result of the following function command execution:
CHARINDEX (' sql ', ' Microsoft SQL Server ')
This function command will return the"Microsoft SQL Server"in"SQL"In This example, the starting position of theCHARINDEXfunction will return"S"in the"Microsoft SQL Server"in the location One.
Next, let's look at this CHARINDEX command:
charindex (' 2000
in this example, CHARINDEX returns zero because the string " 7.0 " cannot be in the " Microsoft SQL Server "is found in the".
The original address; http://bbs.delit.cn/thread-202-1-1.html
Reprint please indicate the source;
Author: metric Technology http://www.delit.cn
charindex function usage in SQL statements