以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  清除重复项  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=105051)

--  作者:1186
--  发布时间:2017/8/10 16:46:00
--  清除重复项

Dim idx As String = "-1,"
Dim idx_temp As String = ""
Dim pdr As DataRow = Nothing
Dim count As Integer = 0
Dim cs As String = "工单单号"
For Each dr As DataRow In DataTables("生产主计划").Select("工单单号 is not null", cs)
    Dim flag As Boolean = False
    If pdr IsNot Nothing Then
        For Each c As String In cs.split(",")
            If pdr(c) <> dr(c) Then
                flag = True
                Exit For
            End If
        Next
        If flag Then
            If count > 1 Then
                idx &= idx_temp
            End If
            count = 1
            idx_temp = ""
        Else
            count += 1
            idx_temp &= dr("_Identify") & ","
        End If
    Else
        count += 1
    End If
    pdr = dr
Next
If count > 1 Then
    idx &= idx_temp
End If
DataTables("生产主计划").DeleteFor("_Identify In (" & idx.trim(",") & ")")

 

 

现有排重代码如上。

两条数据相同的工单单号,一条“生管人员”字段有值,一条没有值,优先取有值的。如果两条都没值,随机取一条。

这个要怎么写代码?


--  作者:有点甜
--  发布时间:2017/8/10 17:07:00
--  

 

For Each dr As DataRow In DataTables("生产主计划").Select("工单单号 is not null", cs & ",生管人员 desc")