你已经在上面取出w打头记录的例子中看到了LIKE的用法。LIKE判定词是一个非常有用的符号。不过,在很多情况下用了它可能会带给你太多的数据,所以在用到它之前最好先开动脑筋多想想自己到底想获得什么数据。假设你想取出5位数字的SKU号码,而且其开头是1结尾是5,那么你可以用下划符(_)代替%符号: SQL = "SELECT * FROM Products WHERE p_sku LIKE '1___5'"
以下面的SQL语句为例: SQL ="SELECT c_firstname, c_lastname, c_email FROM customers WHERE c_email IS NOT NULL AND c_purchase = '1' OR c_purchase = '2' AND c_lastname LIKE 'A%'"
多行语句 在SQL语句不好懂的情况下,你不妨把整个语句分解为多行代码,然后在现有变量基础上逐步增加查询语句的各个组成部分并把它存在同一变量内: SQL = "SELECT c_firstname, c_lastname, c_emailaddress, c_phone" SQL = SQL " FROM customers" SQL = SQL " WHERE c_firstname LIKE 'A%' and c_emailaddress NOT NULL" SQL = SQL " ORDER BY c_lastname, c_firstname" 到了最后一句,SQL变量就包含了以下的完整SELECT 语句: "SELECT c_firstname, c_lastname, c_emailaddress, c_phone FROM customers WHERE c_firstname LIKE 'A%' and c_emailaddress NO NULL ORDER BY c_lastname, c_firstname"