有两个ID字段 ID1序号已添加好,如何给具有同样ID1的ID2添加序号,语句怎样写,请高人指点,最好详细点,我水平很差的ID1     ID2
1       1
1       2
1       3
2       1
2       2

解决方案 »

  1.   

    Dim intTmp As Integer
    Dim m As Integer
    rs.open "select id,id1 from table order by id1 asc", conn, 1, 1
    If Not rs.EOF Then
        intTmp = rs("id1")
        m = 1
        conn.execute ("update table set id2=" & m & " where id=" & rs("id"))
        rs.movenext
        If Not rs.EOF Then
            For i = 2 To rs.recordcount
                If rs("id1") = intTmp Then
                    m = m + 1
                Else
                    m = 1
                    intTmp = rs("id1")
                End If
                conn.execute ("update table set id2=" & m & " where id=" & rs("id"))
            Next
        End If
    End If