【译文】查询限制结果记录集(二)-周芳
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-查询/SQL语句


【译文】查询限制结果记录集(二)

发表时间:2014/3/10 9:15:01 评论(0) 浏览(4922)  评论 | 加入收藏 | 复制
   
摘 要:查询限制结果记录集
正 文:

来自:微软    翻译:周芳


【译文】查询限制结果记录集(二)

      通常情况下,你不会想从表中检索出所有记录。你只想要得到这些记录中基于一些符合条件标准的一个子集。由此可以限定一个Select语句,这时您必须使用Where子句,这将允许您指定出哪些是你想检索的记录。

VBA
Select *
    FROM tblInvoices
    Where CustomerID = 1


      要明白CustomerID = 1的Where子句的一部分。 Where子句可以包含>40这样的表达式,并且可与and或or 这些逻辑运算符结合。使用多个表达式可以让您进一步过滤记录的结果集。

VBA
Select *
    FROM tblInvoices
    Where CustomerID = 1 AND InvoiceDate > #01/01/98#


      请注意日期字符串需要加上数字符号(#)。如果您使用的是普通的字符串表达式,你必须在该字符串附上单引号('),例如:

VBA
Select *
    FROM tblCustomers
    Where [Last Name] = 'White'


      如果你不知道整个字符串值,您可以使用 Like 通配符。

Select *
    FROM tblCustomers
    Where [Last Name] LIKE 'W*'



【原文】Restricting the Result Set

More often than not, you will not want to retrieve all records from a table. You will want only a subset of those records based on some qualifying criteria. To qualify a Select statement, you must use a Where clause, which will allow you to specify exactly which records you want to retrieve.

VBA
Select *
    FROM tblInvoices
    Where CustomerID = 1

Be aware of the CustomerID = 1 portion of the Where clause. A Where clause can contain up to 40 such expressions, and they can be joined with the And or or logical operators. Using more than one expression allows you to further filter out records in the result set.

VBA
Select *
    FROM tblInvoices
    Where CustomerID = 1 AND InvoiceDate > #01/01/98#


Be aware that the date string is enclosed in number signs (#). If you are using a regular string in an expression, you must enclose the string in single quotation marks ('). For example.

VBA
Select *
    FROM tblCustomers
    Where [Last Name] = 'White'

If you do not know the whole string value, you can use wildcard characters with the Like operator.

Select *
    FROM tblCustomers
    Where [Last Name] LIKE 'W*'



Access软件网交流QQ群(群号:198465573)
 
 相关文章
【译文】为什么使用Access作为开发工具  【周芳(译)  2013/12/17】
【译文】如何用ADO代码实现窗体记录集的绑定  【周芳  2013/12/24】
【译文】如何检索已安装打印机的列表  【周芳  2013/12/31】
【译文】如何输出报表到XML文件  【周芳  2014/1/27】
【译文】如何使用Access SQL 检索记录(一)  【周芳  2014/2/17】
常见问答
技术分类
相关资源
文章搜索
关于作者

周芳

文章分类

文章存档

友情链接