我在 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%,因此我尝试了以下操作,但我不断收到错误消息(“查询表达式中的语法错误”)并且它没有指定错误发生在哪一行on,它只返回整个代码。
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()
,但所做的只是以随机顺序返回前 10%。在Visual Basic 中写SQL 时不能使用Tablesample 命令吗?