Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-查询/SQL语句

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

时 间:2014-03-10 09:15:01
作 者:周芳   ID:24526  城市:上海
摘 要:查询限制结果记录集
正 文:

来自:微软    翻译:周芳


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

      通常情况下,你不会想从表中检索出所有记录。你只想要得到这些记录中基于一些符合条件标准的一个子集。由此可以限定一个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群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助