Foxtable(狐表)用户栏目专家坐堂 → 如何删除同表同两个字段相同的记录,只保留一条?


  共有1693人关注过本帖树形打印复制链接

主题:如何删除同表同两个字段相同的记录,只保留一条?

帅哥哟,离线,有人找我吗?
苍风霁月
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:704 积分:7058 威望:0 精华:0 注册:2012/11/4 23:10:00
如何删除同表同两个字段相同的记录,只保留一条?  发帖心情 Post By:2016/11/3 12:52:00 [只看该作者]

求思路!谢谢!

 回到顶部
帅哥哟,离线,有人找我吗?
有点青
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:573 积分:2961 威望:0 精华:0 注册:2016/10/27 14:33:00
  发帖心情 Post By: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(",") & ")")


 回到顶部