以文本方式查看主题
- Foxtable(狐表) (http://foxtable.net/bbs/index.asp)
-- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2)
---- 筛选 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=193317)
|
-- 作者:1234567
-- 发布时间:2024/9/4 13:05:00
-- 筛选
如何筛选出不同【零件编号】的最后【完成日期】行? 此主题相关图片如下:3.png
|
-- 作者:狐狸爸爸
-- 发布时间:2024/9/4 14:12:00
--
例如:
sele ct 编号,max(日期) from {表B} group by 编号
|
-- 作者:1234567
-- 发布时间:2024/9/4 15:45:00
--
我要找出零件编号为A,完成日期为最近的行,零件编号为B,完成日期为最近的行.......
是否采用For Each 语句,代码怎么写?
|
-- 作者:1234567
-- 发布时间:2024/9/4 17:20:00
--
Dim Filter As String = "零件编号 = \'\'" Dim Products As List(Of String) Products = DataTables("表A").GetValues("零件编号") \'找出不同的零件编号 For Each Product As String In Products Filter = Filter & " And " Filter = Filter & "(零件编号 = \'" & Product & "\' AND 完成日期 = \'" & Max(完成日期) & "\')"\'找出不同零件编号的最近完成日期行 Next If Filter > "" Then Tables("表A").Filter = Filter \'筛选出不同零件编号的最近完成行 End If
老师,上述代码的思路是否正确,帮我改一下代码?
|
-- 作者:狐狸爸爸
-- 发布时间:2024/9/5 8:57:00
--
Dim drs As List(Of DataRow) = DataTables("表B").Select("", "编号,日期 Desc") Dim rst As New List(Of DataRow) Dim bh As String = "" For Each dr As DataRow In drs If dr("编号") <> bh Then rst.Add(dr) bh = dr("编号") End If Next
rst就是要的结果。
|
-- 作者:1234567
-- 发布时间:2024/9/5 10:25:00
--
Dim drs As List(Of DataRow) = DataTables("表A").Select("", "零件编号,完成日期 Desc") Dim rst As New List(Of DataRow) Dim bh As String = "" For Each dr As DataRow In drs If dr("零件编号") <> bh Then rst.Add(dr) bh = dr("零件编号") Dim Filter As String = "工艺单号 = \'\'" Filter = Filter & " And " Filter = Filter & "工艺单号 = \'" & drs("工艺单号") & "\'" End If Next If Filter > "" Then Tables("生产管理_Table01").Filter = Filter End If
此主题相关图片如下:8.png
|
-- 作者:狐狸爸爸
-- 发布时间:2024/9/5 10:51:00
--
Filter = Filter & "工艺单号 = \'" & dr("工艺单号") & "\'"
|
-- 作者:1234567
-- 发布时间:2024/9/5 11:01:00
--
Dim drs As List(Of DataRow) = DataTables("表A").Select("", "零件编号,完成日期 Desc") Dim rst As New List(Of DataRow) Dim bh As String = "" For Each dr As DataRow In drs If dr("零件编号") <> bh Then rst.Add(dr) bh = dr("零件编号") Dim Filter As String = "工艺单号 = \'\'" Filter = Filter & " And " Filter = Filter & "工艺单号 = \'" & dr("工艺单号") & "\'" If Filter > "" Then Tables("表A").Filter = Filter End If End If Next
筛选的结果生成的表是空的
|
-- 作者:狐狸爸爸
-- 发布时间:2024/9/5 11:25:00
--
检查一下合成的Filter内容是什么
|
-- 作者:1234567
-- 发布时间:2024/9/5 12:27:00
--
Dim drs As List(Of DataRow) = DataTables("表A").Select("", "零件编号,完成日期 Desc") Dim rst As New List(Of DataRow) Dim bh As String = "" For Each dr As DataRow In drs If dr("零件编号") <> bh Then rst.Add(dr) bh = dr("零件编号") MsgBox(bh) Dim Filter As String = "工艺单号 = \'\'" MsgBox(Filter) Filter = Filter & " or " MsgBox(Filter) Filter = Filter & "工艺单号 = \'" & dr("工艺单号") & "\'" MsgBox(Filter) If Filter > "" Then Tables("表A").Filter = Filter End If End If Next
合成的Filter分别是如下内容,我希望的合成结果是工艺单=\'\' or工艺单=\'A-03\'or工艺单=\'B-03\'
A 工艺单=\'\' 工艺单=\'\' or 工艺单=\'\' or工艺单=\'A-03\'
B 工艺单=\'\' 工艺单=\'\' or 工艺单=\'\' or工艺单=\'B-03\'
|