我在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命令?
答案 0 :(得分:0)
Access将反对子查询中的FROM
子句:
FROM QC_File As DUPE Tablesample(10 PERCENT)
Access SQL不支持 Tablesample()
。
我建议你构建一个新的Access查询,它可以从子查询中完成你想要的。一旦你有了这个工作,就用它作为子查询。