如何在 Access 中使用 WITH 语句? [英] How do I use the WITH statement in Access?

查看:168
本文介绍了如何在 Access 中使用 WITH 语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Access 并希望通过命名 SELECT 语句来简化我的一些查询.但是,由于某种原因,我不能使用 WITH 语句.我尝试运行以下简单示例来说明问题:

I'm using Access and would like to simplify some of my queries by naming SELECT statements. However, I can't use the WITH statement for some reason. I have tried running the following simple example to illustrate the problem:

WITH T1 AS
(
SELECT * FROM [Transactions]
)
SELECT * FROM T1;

其中 Transactions 是日期和金额表.当我运行此查询时,出现以下错误:

Where Transactions is a table of dates and amounts. When I run this query I get the following error:

无效的 SQL 语句;应为删除"、插入"、过程"、选择"或更新"

Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'

我做错了什么?

推荐答案

正如其他人在评论中所述,Access SQL 不像 TSQL 那样支持 with 关键字.您可以通过编写第一个查询并保存它来完成几乎相同的事情.然后可以在 Access SQL 中引用保存的查询,就像它是一个表一样(类似于在 TSQL 中创建视图).

As others have stated in the comments, Access SQL does not support the with keyword the same way that TSQL does. You can accomplish close to the same thing though by writing the first query and saving it. The saved query can then be referenced in your Access SQL as though it was a table (similar to creating a view in TSQL).

其他人还指出,VBA 可以使用 with 关键字,但用途不同.

Others also noted that VBA can use the with keyword, but for a different purpose.

这篇关于如何在 Access 中使用 WITH 语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆