sql = "select IDNO from account_history group by IDNO where flag=2"     '查询修改过的记录
        Dim rs As New ADODB.Recordset
        Set rs = New ADODB.Recordset
        Set rs = Conn.Execute(sql)
        If Not rs.EOF Then
            Do While Not rs.EOF
                Conn.Execute ("delete account_history where idno='" & rs("idno") & "' and flag=0 ") '删除曾经修改的记录
            rs.MoveNext
            Loop
        End If

解决方案 »

  1.   

    sql = "select IDNO from account_history group by IDNO where flag=2"     '查询修改过的记录
    顺序错啦!!
    sql = "select IDNO from account_history where flag=2 group by IDNO"     '查询修改过的记录
      

  2.   

    假设IDNO是你的数据表的主键,flag是你的数据是否修改的标志,而且只有一个flag字段
    如果flag 为2 表示修改过那你后面的语句
    delete account_history where idno='" & rs("idno") & "' and flag=0 
    就和前面矛盾,其实什么也没删掉啊你的代码不知道是什么意思
      

  3.   

    delete from account_history where .....
    delete 语句最好加 from 啦
      

  4.   

    sql = "select IDNO from account_history group by IDNO where flag=2"             Dim rs As  ADODB.Recordset
    Set rs = New ADODB.Recordset
    rs.open sql,Conn,adOpenKeyset, adLockOptimistic, adCmdText
    Do While Not rs.EOF
       Conn.Execute "delete account_history where idno='" & rs!idno & "' and flag=0" 
       rs.MoveNext
    Loop
    rs.close
    set rs=nothing
      

  5.   

    对and flag=0 是矛盾了,不应该有的吧
      

  6.   

    其实一句就能搞定呀:
    Conn.execute "delete account_history where flag=0 and idno in(select idno from account_history group by IDNO where flag=2)"