MS Access SQL-一个表中的更新字段,其中包含另一表中的计数

时间:2020-08-26 11:29:51

标签: sql ms-access

我有一个名为“ FilesUploaded”的表,该表汇总了上传到访问数据库的所有文件。我想在此处添加一个字段,其中包含来自另一个表的所有错误的计数。

  • 我的FilesUploaded表包含一个名为“ FileName”的字段,该字段具有 文件的全名。
  • 我想对“ ValidityCheck”字段包含“ Error”的表1中的所有记录进行计数。 Table1还包含一个名为“ Name_of_Report”的字段,该字段的文件名将与FilesUploaded表匹配。
  • “ vFileName”变量将包含“ Filename”字段和“ Name_of_Report”字段中的内容

下面是我尝试使用的代码,但是它说不允许这种类型的连接,我不知道还有什么其他方法可以实现此目的。

Call RunSQL("UPDATE FilesUploaded " & _
    "LEFT JOIN (SELECT table1.Name_of_Report, Sum(IIf([table1].[ValidityCheck] Like '*Error*',1,0)) AS ErrorCount FROM table1 GROUP BY table1.Name_of_Report) AS temp on temp.Name_of_Report = FilesUploaded.FileName " & _
    "SET " & _
    "FilesUploaded.[ErrorCount] = temp.ErrorCount " & _
    "WHERE FilesUploaded.[FileName] = '" & vFileName & "' ")

有人知道有其他方法可以使用Table1表中的ValidityCheck字段来更新FilesUploaded表吗?

提前坦克

1 个答案:

答案 0 :(得分:0)

在MS Access中,Running Gradle task 'assembleDebug'... Parameter format not correct - error: error reading C:\Users\utilisateur\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\20.0\89507701249388e1ed5ddcf8c41f4ce1be7831ef\guava-20.0.jar; error in opening zip file error: error reading C:\Users\utilisateur\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\20.0\89507701249388e1ed5ddcf8c41f4ce1be7831ef\guava-20.0.jar; error in opening zip file C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\google_sign_in-4.1.4\android\src\main\java\io\flutter\plugins\googlesignin\BackgroundTaskRunner.java:7: error: package com.google.common.util.concurrent does not exist import com.google.common.util.concurrent.ListenableFuture; ^ C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\google_sign_in-4.1.4\android\src\main\java\io\flutter\plugins\googlesignin\BackgroundTaskRunner.java:8: error: package com.google.common.util.concurrent does not exist import com.google.common.util.concurrent.SettableFuture; ^ C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\google_sign_in-4.1.4\android\src\main\java\io\flutter\plugins\googlesignin\BackgroundTaskRunner.java:75: error: cannot find symbol public <T> ListenableFuture<T> runInBackground(final Callable<T> task) { ^ symbol: class ListenableFuture location: class BackgroundTaskRunner C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\google_sign_in-4.1.4\android\src\main\java\io\flutter\plugins\googlesignin\GoogleSignInPlugin.java:23: error: package com.google.common.base does not exist import com.google.common.base.Joiner; ^ C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\google_sign_in-4.1.4\android\src\main\java\io\flutter\plugins\googlesignin\GoogleSignInPlugin.java:24: error: package com.google.common.base does not exist import com.google.common.base.Strings; ^ C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\google_sign_in-4.1.4\android\src\main\java\io\flutter\plugins\googlesignin\BackgroundTaskRunner.java:57: error: cannot find symbol final ListenableFuture<T> future = runInBackground(task); ^ symbol: class ListenableFuture location: class BackgroundTaskRunner C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\google_sign_in-4.1.4\android\src\main\java\io\flutter\plugins\googlesignin\BackgroundTaskRunner.java:76: error: cannot find symbol final SettableFuture<T> future = SettableFuture.create(); ^ symbol: class SettableFuture location: class BackgroundTaskRunner C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\google_sign_in-4.1.4\android\src\main\java\io\flutter\plugins\googlesignin\BackgroundTaskRunner.java:76: error: cannot find symbol final SettableFuture<T> future = SettableFuture.create(); ^ symbol: variable SettableFuture location: class BackgroundTaskRunner C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\google_sign_in-4.1.4\android\src\main\java\io\flutter\plugins\googlesignin\GoogleSignInPlugin.java:247: error: cannot find symbol if (!Strings.isNullOrEmpty(hostedDomain)) { ^ symbol: variable Strings location: class Delegate C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\google_sign_in-4.1.4\android\src\main\java\io\flutter\plugins\googlesignin\GoogleSignInPlugin.java:454: error: cannot find symbol String scopesStr = "oauth2:" + Joiner.on(' ').join(requestedScopes); ^ symbol: variable Joiner 10 errors FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':google_sign_in:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 2m 30s Exception: Gradle task assembleDebug failed with exit code 1 要求其类似的UPDATE...JOINupdateable。使用SELECT...JOIN的汇总查询不是可更新查询。因此,请像SUM那样考虑domain functions

此外,考虑存储的查询,并通过QueryDefs在带有参数化的VBA中调用它。请注意使用DSum来对通配符使用ALIKE,以防万一您需要在MS Access GUI外部运行查询,例如在无法识别%的ODBC或OLEDB连接中运行。< / p>

SQL (另存为存储的查询)

*

VBA (运行不带字符串连接的查询)

PARAMETERS paramFileName TEXT;
UPDATE FilesUploaded f
SET f.[ErrorCount] = DSUM("*", "table1", 
                          "[ValidityCheck] ALIKE '%Error%' AND [Name_of_Report]='" & f.[FileName] & "'")
WHERE f.[FileName] = [paramFileName];
相关问题