使用Tablesample的Visual Basic RunSQL语法错误(Visual Basic RunSQL Syntax error using Tablesample)

编程入门 行业动态 更新时间:2024-10-27 21:13:19
使用Tablesample的Visual Basic RunSQL语法错误(Visual Basic RunSQL Syntax error using Tablesample)

我在Microsoft Access中有一个表单从文本文件导入记录到表中。 原始代码是这样的:

DoCmd.RunSQL "UPDATE QC_File SET QC_File.ToQC = 'x' " & _ "WHERE (((QC_File.ID) In (Select TOP " & VarPer & " PERCENT ID " & _ "FROM QC_File As DUPE " & _ "WHERE [DUPE].[HIST_USUS_ID] = [QC_File].[HIST_USUS_ID] And [DUPE].[Client1] = 'CLIENT' " & _ "ORDER BY [DUPE].[ID] DESC;)))"`

当我希望它随机拉10%时,这个代码只占据了TOP 10%所以我尝试了以下但我不断收到错误(“查询表达式中的语法错误”)并且它没有指定错误发生的行在,它只返回整个代码。

DoCmd.RunSQL "UPDATE QC_File SET QC_File.ToQC = 'x' " & _ "WHERE (((QC_File.ID) In (Select ID " & _ "FROM QC_File As DUPE Tablesample(10 PERCENT) " & _ "WHERE [DUPE].[HIST_USUS_ID] = [QC_File].[HIST_USUS_ID] And [DUPE].[Client1] = 'CLIENT' " & _ "ORDER BY [DUPE].[ID] DESC;)))"

我已经尝试过使用NEWID()但所有这一切都是以随机顺序返回TOP 10%。 在Visual Basic中编写SQL时是否无法使用Tablesample命令?

I have a form in Microsoft Access that imports records into a table from text files. The original code is this:

DoCmd.RunSQL "UPDATE QC_File SET QC_File.ToQC = 'x' " & _ "WHERE (((QC_File.ID) In (Select TOP " & VarPer & " PERCENT ID " & _ "FROM QC_File As DUPE " & _ "WHERE [DUPE].[HIST_USUS_ID] = [QC_File].[HIST_USUS_ID] And [DUPE].[Client1] = 'CLIENT' " & _ "ORDER BY [DUPE].[ID] DESC;)))"`

This code is only grabbing the TOP 10 percent when I want it to pull a random 10 percent so I tried the following but I keep getting an error ("Syntax error in query expression" ) and it does not specify what line the error is occuring on, it just returns the whole code.

DoCmd.RunSQL "UPDATE QC_File SET QC_File.ToQC = 'x' " & _ "WHERE (((QC_File.ID) In (Select ID " & _ "FROM QC_File As DUPE Tablesample(10 PERCENT) " & _ "WHERE [DUPE].[HIST_USUS_ID] = [QC_File].[HIST_USUS_ID] And [DUPE].[Client1] = 'CLIENT' " & _ "ORDER BY [DUPE].[ID] DESC;)))"

I already tried using NEWID() but all that does is return the TOP 10 Percent in random order. Is it not possible to use the Tablesample command when writing SQL in Visual Basic?

最满意答案

Access将在子查询中反对此FROM子句:

FROM QC_File As DUPE Tablesample(10 PERCENT)

Access SQL不支持Tablesample() 。

我建议你构建一个新的Access查询,它可以从子查询中完成你想要的。 一旦你有了这个工作,就用它作为子查询。

Access will object to this FROM clause in the subquery:

FROM QC_File As DUPE Tablesample(10 PERCENT)

Tablesample() is not supported in Access SQL.

I suggest you build a new Access query which accomplishes what you want from the subquery. Once that you have that working, use it as the subquery.

更多推荐

本文发布于:2023-08-02 15:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1378645.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语法错误   Basic   Tablesample   Visual   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!