Parsing of the CHARINDEX function usage in SQL Server (searching for characters or strings in a paragraph-----returning expression1 where the expression2 appears; Conversely, return 0)

Source: Internet
Author: User

70651358

Knowledge Point one: CHARINDEX () syntax

        CHARINDEX ( expression1 , expression2 [ , start_location ] )解析:    expression1 必需 ---要查找的子字符串    expression2 必需 ---父字符串    start_location 可选 ---指定从父字符串开始查找的位置,默认位置从1开始

Knowledge Point two: The role of CHARINDEX ()

    从expression2字符串中指定的位置处开始查找是否包含expression1字符串
    • 1

Knowledge Point three: The return value of CHARINDEX ()

    如果能够从expression2字符串中查找到expression1字符串则返回expression1在    expression2出现的位置;反之,返回0
    • 1
    • 2

Knowledge Point Four: example demonstration

1. Include:

select CHARINDEX(‘cd‘,‘abcdefg‘)
    • 1

The result is: 3

2. Does not include:

select CHARINDEX(‘dc‘,‘abcdefg‘)
    • 1

The result is: 0

Knowledge Point Four: The parameters of charindex () are case insensitive

Case:

select CHARINDEX(‘bCD‘,‘abcdefg‘)
    • 1

The result is: 2

Parsing of the CHARINDEX function usage in SQL Server (searching for characters or strings in a paragraph-----returning expression1 where the expression2 appears; Conversely, return 0)

Related Article

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.