2013-10-15 34 views
2

我對訪問的工作原理知之甚少,但我需要一些更有效的方法,那麼我現在正在做什麼。同時在Access中進行多個更新

我有這些疑問:

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#)); 

問題是我必須單獨運行它們。有沒有一種方法可以將它們組合成一個查詢?任何幫助表示讚賞。

回答

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) 
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(R.[Receipt Date]) = 404不工作,那麼嘗試:

WHERE Right(R.[Receipt Date],3) = '404' 
1

不幸的是Microsoft Access不能同時運行多個查詢。你有兩種我能想到的方法。

  • [寫微距]或VBA程序1

您可以創建執行特定的一系列操作的宏,並 您可以創建一個宏組進行相關係列動作。

在Microsoft Office Access 2007中,可以將宏包含在宏 對象(有時稱爲獨立宏)中,也可以將 嵌入到窗體,報表或控件的事件屬性中。嵌入式 宏成爲嵌入式對象或控件的一部分。宏對象在導航窗格中可見,在 宏下;嵌入的宏不是。

但是,其他路線可能會好得多。因爲您不必在Access內部運行宏。

  • 編寫一個查詢程序:

這樣你可以寫一個程序,將物理連接到數據庫;那麼該程序可以完成繁重的工作。這也會給你更多的控制權。然後一個實際的編程語言將被操縱。

不知道這些幫助,我實際上有一個類似的示例項目 - 我將它發佈到Git並在此處爲您編輯它。

+0

那太棒了!總是非常有幫助。 – JLott

+0

我試圖記住我在我們的辦公網絡上放置源文件的位置;只要我找到它,我會將它發佈到GIT上供您查看。 – Greg