For the SQL field "include" and "include" string

Source: Internet
Author: User

For the SQL field "include" and "include" string
Zookeeper

1. Method for querying all records whose field value "contains" a string

If the table has a name field and the query name contains all records of "Zhang San", you can write the SQL statement as follows:

Stirng strsql = "SELECT * FROM table name WHERE name LIKE '%" + "Zhang San" + "% '";

2. How to query all records with a field value "included in" a string

If the name field in the query table contains all the records of the string "John is a good student", you can write the SQL statement as follows:

String strsql = "SELECT * FROM table name where instr ('John is a good student ', name)> 0 ";

You can query all the records. The name field values in the record include: sheet, 3, yes, item, good, student, student, Michael, and so on.

Note: In the preceding SQL string, change the fullwidth symbol to the halfwidth symbol.


How to include SQL query field values in strings

Can't I use charindex? In fact, it is very simple. Your logic is that the returned data should be found in the string you provide. You can see if this is the case:
Select * from
Where
CHARINDEX (substring (value, 1, 1), 'a, B, d, e') <> 0
And
CHARINDEX (substring (value, 2, 1), 'a, B, d, e') <> 0
And
CHARINDEX (substring (value, 3, 1), 'a, B, d, e') <> 0
 
In SQL statements, how do I write a statement that finds a field containing a string?

Select filename from oa_file where filename like '%? % ';
You must have no problem with this sentence. The possible problem is that the question mark is different from the question mark!
For example, the question mark at the halfwidth of an English Punctuation Mark is "?", The question mark of the English Punctuation is "?"
But the question mark in Chinese is "?" Question mark (?)
These are different. All the files you found contain English question marks.
The above is my idea.

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.