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
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
顺序错啦!!
sql = "select IDNO from account_history where flag=2 group by IDNO" '查询修改过的记录
如果flag 为2 表示修改过那你后面的语句
delete account_history where idno='" & rs("idno") & "' and flag=0
就和前面矛盾,其实什么也没删掉啊你的代码不知道是什么意思
delete 语句最好加 from 啦
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
Conn.execute "delete account_history where flag=0 and idno in(select idno from account_history group by IDNO where flag=2)"