3

我有两个相互关联的表:QUOTERunQUOTERunResults. QUOTERun包含特定报价所需的所有项目。 QUOTERunResults包含所有供应商响应的记录。我有一个程序可以分析这些响应并选择最合适的供应商并将一个名为Prefferedtrue 的字段设置为。有时没有一个供应商会工作。我需要创建一个所有记录的列表,QUOTERun其中没有QUOTERunResults标记为首选的匹配记录。

这是我到目前为止所拥有的

Set rs1 = CurrentDb.OpenRecordset("SELECT ReferenceNumber FROM [QUOTERun] WHERE RunID = " & TempRunID, dbOpenDynaset)
Set rs2 = CurrentDb.OpenRecordset("SELECT ReferenceNumber, Preffered FROM [QUOTERunResults] " & _
                                  "WHERE RunID = " & TempRunID & " AND Preffered = True", dbOpenDynaset)
If (rs2.RecordCount = 0) Then
   TempListNotComplete = "NONE OF THE VENDOR RESPONSES HAD ENOUGH STOCK. NO RECORDS HAVE BEEN MARKED AS PREFFERED."
ElseIf (rs1.RecordCount <> 0) Then
   rs1.MoveFirst
   Do While rs1.EOF <> True
      rs2.FindFirst "ReferenceNumber = " & rs1.Fields("[ReferenceNumber]").value
      If (rs2.Fields("[ReferenceNumber]").value <> rs1.Fields("[ReferenceNumber]").value) Then
         If (TempListNotComplete = "") Then 
            TempListNotComplete = rs1.Fields("[ReferenceNumber]").value 
     Else 
            TempListNotComplete = TempListNotComplete & ", " & rs1.Fields("[ReferenceNumber]").value
     End If
      End If
      rs1.MoveNext
   Loop
End If

有没有更有效的方法来做上述事情?

4

1 回答 1

3

您可以在查询设计窗口的 SQL 视图中创建查询:

SELECT a.ReferenceNumber 
FROM
    (SELECT ReferenceNumber 
     FROM [QUOTERun] 
     WHERE RunID = [Enter TempRunID]) a
LEFT JOIN 
    (SELECT ReferenceNumber, Preffered 
     FROM QUOTERunResults 
     WHERE RunID = [Enter TempRunID] AND Preffered = True) b
On a.ReferenceNumber=b.ReferenceNumber
WHERE b.ReferenceNumber Is Null

以上应显示第一个派生表中不在第二个派生表中的所有记录。

于 2012-08-10T15:13:35.687 回答