charindex function usage in SQL statements

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.