SQL charindex Function

Source: Internet
Author: User

The CHARINDEX function returns the starting position of a character or string in another string. The CHARINDEX function is called as follows:

CHARINDEX (expression1, expression2 [, start_location])

Expression1 is the character to be searched in expression2. start_location is the position where the CHARINDEX function starts to find expression1 in expression2.

The CHARINDEX function returns an integer that is the position of the string to be searched in the string to be searched. If CHARINDEX does not find the string to be searched, the function integer is "0 ". Let's take a look at the following function command execution results:

CHARINDEX ('SQL', 'Microsoft SQL Server ')

This function command returns the starting position of "SQL" in "Microsoft SQL Server". In this example, the CHARINDEX function returns position 11 of "S" in "Microsoft SQL Server.
Next, let's look at the CHARINDEX command:

CHARINDEX ('7. 0', 'Microsoft SQL Server 100 ')

In this example, CHARINDEX returns zero because the string "7.0" cannot be found in "Microsoft SQL Server. Next we will take two examples to see how to use the CHARINDEX function to solve the actual T-SQL problem.

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.