Use SQL statements in ASP 3: Like, Not Like and Between

zhaozj2021-02-16  37

You have seen the LIKE usage in the example of remaining the W header record. The Like decision is a very useful symbol. However, in many cases it uses it to bring you too much data, so it is best to open your mind before you use it. Suppose you want to take out the 5-digit SKU number, and the beginning is 1 end is 5, then you can use the underman (_) instead of% symbol:

SQL = "SELECT * from Products where p_sku like '1___5'"

The underscription indicates any character. So in the case of entering "1 _ _ _ 5", your search is limited to the 5-digit range that meets the specific mode.

If you want to be against it, you have to find out the SKU entry that does not match the "1_ _ _ 5" mode. Then you only need to add NOT in front of the LIKE in the examples just now.

Between

Suppose you want to take out some range of data, and you know the starting point and end point in advance, then you may wish to use BetWeen judgment. Let us now assume that you want to select the records between 1 and 10 in a given table. You can use BetWeen as follows:

... WHERE ID BETWEEN 1 and 10

Or you can also use the familiar mathematical judgment sentence:

... WHERE ID> = 1 and ID> = 10

转载请注明原文地址:https://www.9cbs.com/read-21399.html

New Post(0)