How to Use Replace to query whether a specific string is contained

Source: Internet
Author: User
The Replace keyword is mainly used to Replace a character in a string with another character. Today we will introduce you to use it to check whether a specific string is contained. The sample code is as follows, if you are interested, refer to the Replace keyword in sqlserver. It is mainly used to Replace a character in the string with another character. Today, we need to reverse thinking,

The Replace keyword is mainly used to Replace a character in a string with another character. Today we will introduce you to use it to check whether a specific string is contained. The sample code is as follows, if you are interested, refer to the Replace keyword in SQL server. It is mainly used to Replace a character in the string with another character. Today, we need to reverse thinking,

The Replace keyword is mainly used to Replace a character in a string with another character. Today we will introduce you to use it to check whether a specific string is contained. The sample code is as follows, if you are interested, refer

In SQL server, the Replace keyword is mainly used to Replace a character in a string with another character. Today, we need to reverse thinking. It can also be used to query whether a specific string is contained, for example, given the following Dataset

We hope to obtain records containing the "aaa" character from this DataSet. Note that 2nd pieces of data do not contain "aaa", but contain "aaaa ". The expected "" result is as follows:

The traditional thinking is definitely to find out how to contain three a strings. Some people will use like, but this will also be found together with four a strings. Here we will think about replacing the "aaa" in the string with Replace. If it can be replaced, it will prove that the string contains this character. After replacement, it will certainly be different from the original string, therefore, the following SQL statement is released. The Code is as follows:

SELECT * FROM [master]. [dbo]. [Table_5]

Where replace (',' + strNum + ', aaa,', '') <> ',' + strNum + ','

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.