"SQL" CHARINDEX

Source: Internet
Author: User

  Syntax: CHARINDEX (Expressiontofind, Expressiontosearch [, Start_location])

  Parameters:

  1)Expressiontofind

expression that contains the sequence-be found. ' data-guid= ' 31322e138e1f1d142d5ca96d75a5ff74 ' > The character expression that contains the sequence to find. Expressiontofind is limited to 8000 characters. ' data-guid= ' 899380d9ea95b67c4092a730c1a0cee0 ' > The Expressiontofind contains a maximum of 8,000 characters.

  2) Expressiontosearch

The character expression to search for.

  3) start_location

integer or span class= "input" >bigint expression at which the search starts. ' Data-guid= ' D1a17b9ccae54b7655b14b3efe985bbe ">   that represents the starting position of the search; integer   or   bigint   expression.   start_location is not specified, is a negative numb Er, or is 0, the search starts at the beginning of expressiontosearch . ' Data-guid= ' 2187f677 f256c74b1eb14421d824788a "> If  start_location is not specified, the parameter is negative or 0, the  expressiontosearch   starts the search.

start_location is isn't specified, is a negative number, or was 0, the search starts at the beginning of Express Iontosearch. ' data-guid= ' 2187f677f256c74b1eb14421d824788a ' > return value:

start_location is isn't specified, is a negative number, or was 0, the search starts at the beginning of Express Iontosearch. ' data-guid= ' 2187f677f256c74b1eb14421d824788a ' >   if expressiontosearch has varchar (max),nvarchar ( max), or varbinary (max) data type, returns bigint; .

start_location is isn't specified, is a negative number, or was 0, the search starts at the beginning of Express Iontosearch. ' data-guid= ' 2187f677f256c74b1eb14421d824788a > Example one:

start_location is isn't specified, is a negative number, or was 0, the search starts at the beginning of Express Iontosearch. ' data-guid= ' 2187f677f256c74b1eb14421d824788a >  customname contains the customer's first name and last Name, separated by a space between them. We use the CHARINDX function to determine the position of the middle space of two names. With this method, we can parse the space position of the ContactName column so that only the last name part of the column can be displayed.

Select Top 5 substring (ContactName,charindex(', ContactName)+1,lenas  [lastName] from Customers

Example two:

Calculates the number of records in the Addresses field in the Northwind.dbo.Customer table that contain the word road or its abbreviation Rd, similar to the SELECT statement:

 select  count  ( Span style= "COLOR:RGB (128, 128, 128); >* ) where  charindex  ( rd   ' , Address ' >  0  or  charindex  ( " road  >  1  

reference: http:// www.cnblogs.com/smhy8187/articles/930929.html

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.