以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何删除同表同两个字段相同的记录,只保留一条?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=92440)

--  作者:苍风霁月
--  发布时间:2016/11/3 12:52:00
--  如何删除同表同两个字段相同的记录,只保留一条?
求思路!谢谢!
--  作者:有点青
--  发布时间:2016/11/3 13:39: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("表A").Select("", cs)
    Dim flag As Boolean = False
    If pdr IsNot Nothing Then
        For Each c As String In cs.split(",")
            If pdr(c).replace(" ","") <> dr(c).replace(" ", "") 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("表A").DeleteFor("_Identify not In (" & idx.trim(",") & ")")