Method for Determining whether a string contains a substring

Source: Internet
Author: User
By using the flexible use of the CHARINDEX, PATINDEX, and wildcard functions, we can determine that the method containing the sub-string in the string does not have source code and Demonstration: Source Code 1. query whether the string contains non-numeric characters SELECTPATINDEX (% [^ 0-9] %, 1235X461) SELECTPATINDEX (% [^ 0-9] %, 12350461) 2. query whether a package is included in a string

By using the flexible use of the CHARINDEX, PATINDEX, and wildcard functions, we can determine that the method containing the sub-string in the string does not have source code and Demonstration: Source Code 1. whether the query string contains the non-numeric character select patindex ('% [^ 0-9] %', '1235x461 ') select patindex (' % [^ 0-9] % ', '123') 2. query whether a package is included in a string

Using the flexible use of the CHARINDEX, PATINDEX, and wildcard functions, we can determine the method for containing a substring in a string. <无>

Source code and demo:Source code

1. whether the query string contains the non-numeric character select patindex ('% [^ 0-9] %', '1235x461 ') select patindex (' % [^ 0-9] % ', '123') 2. query whether the string contains the numeric character select patindex ('% [0-9] %', 'suyllgoo') select patindex ('% [0-9] % ', 'suyllpolico') 3. the FUNCTION determines that the string only contains the number create function [dbo]. fn_IsNumeric (@ pString VARCHAR (8000) RETURNS bitWITH ENCRYPTIONASBEGINDECLARE @ vJudge intSET @ vJudge = 0 SELECT @ vJudge = casewhen patindex ('% [0-9] % ', LOWER (@ pString)> 0 THEN 0 when patindex ('% [0-9] %', LOWER (@ pString )) = 0 THEN 1 ENDRETURN @ vJudgeEND4. the FUNCTION determines that the string only contains letters (case-insensitive) create function [dbo]. fn_IsAlpha (@ pString VARCHAR (8000) RETURNS bitWITH ENCRYPTIONASBEGINDECLARE @ vJudge intSET @ vJudge = 0 SELECT @ vJudge = casewhen patindex ('% [a-z] % ', LOWER (@ pString)> 0 THEN 0 when patindex ('% [a-z] %', LOWER (@ pString) = 0 THEN 1 ENDRETURN @ vJudgeEND

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.