简体   繁体   English

有条件地从 ms 访问查询 (SQL) 中删除行

[英]Conditionally remove rows from ms access query (SQL)

I would like to remove rows (about 10000) from a report in ms access.我想从 ms 访问的报告中删除行(大约 10000 行)。 I am comparing two sets of two column in a table.我正在比较表中的两组两列。 When I run the query I would like it to remove the rows where column 1 and 3 match and column 2 and 4 match.当我运行查询时,我希望它删除第 1 列和第 3 列匹配以及第 2 列和第 4 列匹配的行。 I have tried running a left join query and trying with vba code but can't get it to work.我尝试运行左连接查询并尝试使用 vba 代码,但无法使其正常工作。

Here is the data这是数据

在此处输入图像描述

I have tried using VBA我试过使用 VBA

Private Sub Report_Open()
   Dim prism_box As String
   Dim prism_recs As String
   Dim keepdrop_box As String
   Dim keepdrop_recs As String

   prism_box = CStr(Me.[tbl_KeepDrop_remainingpackets_RecId])
   prism_recs = CStr(Me.[tbl_KeepDrop_remainingpackets_RecId])
   keepdrop_box = CStr(Me.[Duplicate Recids_Box#])
   keepdrop_recs = CStr(Me.[Duplicate Recids_RecId])

   If prism_box = keepdrop_box & prism_recs = keepdrop_recs Then

   End If
End Sub

I have tried using query too but won't delete them.我也尝试过使用查询,但不会删除它们。

I would like the final result to report a table like this...我希望最终结果报告这样的表格...... 在此处输入图像描述

Since this is a report, you are better off creating a query that excludes what you don't want to see.由于这是一份报告,您最好创建一个排除您不想看到的内容的查询。

Pull in whatever fields you need then create two more fields that have iif([column1] = [column3], True, False) and iif([column2] = [column4], True, False Add into criteria False and then point your report's recordsource at that query. (Change the column1-4 into their actual names)拉入您需要的任何字段,然后再创建两个具有iif([column1] = [column3], True, False)iif([column2] = [column4], True, False的字段添加到标准False中,然后指向您的报告该查询的记录源。(将 column1-4 更改为它们的实际名称)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM