2

我对访问的工作原理知之甚少,但我需要一些比我现在正在做的更有效的事情。

我有这些疑问:

UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] = #04/07/2003#
WHERE ((([Receipt Audit].[Receipt Date])=#4/7/303#));

UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] = #2/27/2004#
WHERE ((([Receipt Audit].[Receipt Date])=#2/27/404#));

UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] =#5/29/2003#
WHERE ((([Receipt Audit].[Receipt Date])=#5/29/303#));

UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] =#8/25/2003#
WHERE ((([Receipt Audit].[Receipt Date])=#8/25/303#));

UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] = #8/28/2003#
WHERE ((([Receipt Audit].[Receipt Date])=#8/28/303#));

UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] = #9/29/2003#
WHERE ((([Receipt Audit].[Receipt Date])=#9/29/303#));

UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] = #2/25/2004#
WHERE ((([Receipt Audit].[Receipt Date])=#2/25/404#));

UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] = #3/30/2004#
WHERE ((([Receipt Audit].[Receipt Date])=#3/30/404#));

UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] = #8/23/2004#
WHERE ((([Receipt Audit].[Receipt Date])=#8/23/404#));

UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] = #8/25/2004#
WHERE ((([Receipt Audit].[Receipt Date])=#8/25/404#));

UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] = #8/26/2004#
WHERE ((([Receipt Audit].[Receipt Date])=#8/26/404#));


UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] = #8/27/2004#
WHERE ((([Receipt Audit].[Receipt Date])=#8/27/404#));

UPDATE [Receipt Audit]
SET [Receipt Audit].[Receipt Date] = #8/30/2004#
WHERE ((([Receipt Audit].[Receipt Date])=#8/30/404#));

问题是我必须单独运行它们。有没有办法可以将它们组合成一个查询?任何帮助表示赞赏。

4

3 回答 3

2

也许是这样的?

UPDATE [Receipt Audit]
SET [Receipt Date] = DateSerial(Switch(Year([Receipt Date])=303,2003,Year([Receipt Date])=404,2004,True,Year([Receipt Date])),Month([Receipt Date]),Day([Receipt Date]))
WHERE Year([Receipt Date]) IN (303,404)
于 2013-10-15T15:28:02.247 回答
1

不幸的是,Microsoft Access 不能同时运行多个查询。你有两种我能想到的方法。

  • [编写宏] 或 VBA 程序1

您可以创建一个宏来执行一系列特定的操作,您可以创建一个宏组来执行相关的一系列操作。

在 Microsoft Office Access 2007 中,宏可以包含在宏对象(有时称为独立宏)中,也可以嵌入到窗体、报表或控件的事件属性中。嵌入的宏成为嵌入它们的对象或控件的一部分。宏对象在导航窗格中的宏下可见;嵌入式宏不是。

但是,另一条路线可能要好得多。因为您不必在 Access 内部运行宏。

  • 编写查询程序:

通过这种方式,您可以编写一个物理连接到数据库的程序;然后程序可以完成繁重的工作。这也将使您对它有更多的控制权。然后一个实际的编程语言将被操纵。

不确定这些是否有帮助,我实际上有一个类似的示例项目 - 我会将其发布到 Git 并在此处为您编辑。

于 2013-10-15T15:43:31.460 回答
0

下面的查询可能很容易针对某一年运行:

UPDATE [Receipt Audit] AS R
SET R.[Receipt Date] = 
DateSerial(
        2004,
        Month(R.[Receipt Date]),
        Day(R.[Receipt Date])
        );
WHERE Year(R.[Receipt Date]) = 404

DateSerial只需更改要更改的每一年的 where 子句和 year 部分。

或者如果Year(R.[Receipt Date]) = 404不起作用,请尝试:

WHERE Right(R.[Receipt Date],3) = '404'
于 2013-10-15T15:40:01.240 回答