The magical character of replace keyword

Source: Internet
Author: User

In SQL Server, the Replace keyword is used primarily to replace a character in a string with another character, and today, in reverse thinking, it can also be used to query whether a particular string is included, for example, given the following dataset

Expect to get records containing "AAA" characters from this dataset, noting that the 2nd data does not contain "AAA", but rather "AAAA". The expected "" results are as follows:

The traditional mindset must be to figure out how to find a string containing 3 A, and some people will look like, but this will be done with 4 a. Here we think of replacing the "AAA" in the string with replace, and if it can be replaced, prove that the string contains this character, and replace it with the original string, so the following SQL is released.

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.