SQL Server: How to search for%, _, [

Source: Internet
Author: User

There are two ways of doing this:

I. Using escape to define an escape character
When a fuzzy query is made using the LIKE keyword, "%", "" "and" [] "are considered to be wildcard characters when they appear separately. In order to query for the presence of a percent sign (%), underscore (), or square bracket ([]) character in a column of a character data type, you need a way to tell the DBMS to treat these characters in a like-sentence as actual values rather than as wildcard characters. The keyword escape allows you to determine an escape character that tells the DBMS that the character immediately following the escape character is considered an actual value.

Such as:

--查询以 % 开头的记录。注:M 为转义字符。SELECT * FROM tableName a WHERE a.field LIKE ‘M%%‘ ESCAPE ‘M‘

Use [] to enclose the characters that need to be escaped.
Such as:

--查询以 % 开头的记录。SELECT * FROM tableName a WHERE a.field LIKE ‘[%]%‘

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

SQL Server: How to search for%, _, [

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.