Usage of substring and charindex in SQL

Source: Internet
Author: User

--The first parameter is the string to be intercepted, the second argument is truncated from the first character, and the third argument is the length of the Intercept.
--For example: Select SUBSTRING (' 12345678 ', 1,4) returns 1234
--Select SUBSTRING (' 12345678 ', 0,4) returns 123
Select SUBSTRING (' 12345678 ', 1,4)

Grammar The CHARINDEX (expression1, Expression2, [start_location]) parameter expression1 An expression that contains the order of the characters to look for. expression1 is an expression of a short character data type classification. expression2 An expression, typically a column that is used to search for a specified sequence. expression2 belongs to the string data type classification. Start_location The starting character position when searching for expression1 in expression2 . If there is no given start_location, but a negative number or 0, the search begins at the beginning of the expression2 .

Select Charindex (' _ ', ' 1767252_ direct success ', 0)--//return 8

Usage of substring and charindex in SQL

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.