Explain the CHARINDEX function in SQL

怪我咯
Release: 2017-04-05 13:11:35
Original
5468 people have browsed it

The CHARINDEX function returns the starting position of a character orstringin another string. The CHARINDEX function calling method is as follows:

     CHARINDEX (expression1, expression2 [, start_location])

    Expression1 is the character to be found in expression2, start_location is the start of the CHARINDEX function Find the position of expression1 in expression2.

The CHARINDEX function returns aninteger. The returned integer is the position of the string to be found in the string being found. If CHARINDEX does not find the string it is looking for, then the function integer "0". Let's take a look at the results of the execution of the following function command:

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

This function command will return the "SQL" in "Microsoft SQL Server" ” starting position, in this example, the CHARINDEX function will return the position 11 of “S” in “Microsoft SQL Server”. Next, let’s look at this CHARINDEX command:

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

In this example, CHARINDEX returns zero because the string "2008" cannot Found in "Microsoft SQL Server". Next, let's take a look at how to use the CHARINDEX function to solve actual T-SQL problems through two examples.



The above is the detailed content of Explain the CHARINDEX function in SQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!