18641 71101 00DF072-1 PTS_001_003 1 0
18642 71101 00DF072-1 PTS_001_003 1 0
18643 71101 00DF072-1 PTS_001_003 1 0
18644 71101 00DF072-1 PTS_001_003 1 0
18645 71101 00DF072-1 PTS_001_003 1 0
18646 71101 00DF072-1 PTS_001_003 1 0
18647 71101 00DF072-1 PTS_001_003 2 0
18648 71101 00DF072-1 PTS_001_003 2 0
如上数据表,现在想要把表中PackageLevel = 1的记录中的OuterQrCodeID更新为PackageLevel = 2的ID。每三条记录跟新一个ID。并逐条打印ID(PackageLevel = 1的)
更新后的表:
ID OrderNo ProductCode PackageRule PackageLevel OuterQrCodeID
18641 71101 00DF072-1 PTS_001_003 1 18647
18642 71101 00DF072-1 PTS_001_003 1 18647
18643 71101 00DF072-1 PTS_001_003 1 18647
18644 71101 00DF072-1 PTS_001_003 1 18648
18645 71101 00DF072-1 PTS_001_003 1 18648
18646 71101 00DF072-1 PTS_001_003 1 18648
18647 71101 00DF072-1 PTS_001_003 2 0
18648 71101 00DF072-1 PTS_001_003 2 0
不知道应该怎么写嵌套,请大神帮忙!
SQL3 = SQL3 + " SELECT * FROM TB_pts_product"
SQL3 = SQL3 + " WHERE (ProductCode = N'00DF072-1') "
SQL3 = SQL3 + " AND (OrderNo = N'071101') AND (PackageLevel = 1)"
SQL3 = SQL3 + " ORDER BY ID"
SQL4 = SQL4 + " SELECT * FROM TB_pts_product"
SQL4 = SQL4 + " WHERE (ProductCode = N'00DF072-1') "
SQL4 = SQL4 + " AND (OrderNo = N'071101') AND (PackageLevel = 2)"
SQL4 = SQL4 + " ORDER BY ID"
While Not tRecSql4.EOF
For i = 1 To 3
While Not tRecSql3.EOF
LBL = tRecSql3
Debug.Print LBL
tRecSql3.MoveNext
Wend
Next i
tRecSql4.MoveNext
Wend
7 个解决方案
#1
你的嵌套写的没错,在for i=1 to 3这层循环里更新数据就行了。
#2
可是问题是在第一个i=1里,tRecSql3数据就列举完毕了EOF了,等到i=2,tRecSql3就没数据了
#3
那你就要增加判断了哦。 如果eof了就跳出去,否则movenext
#4
该怎么写呢?不会啊
#5
While Not tRecSql4.EOF
While Not tRecSql3.EOF
For i = 1 To 3
LBL1 = tRecSql3!id
Debug.Print LBL & "-" & tRecSql4!id
tRecSql3.MoveNext
Next i
tRecSql4.MoveNext
Wend
Wend
#6
While Not tRecSql4.EOF
While Not tRecSql3.EOF
For i = 1 To 3
LBL1 = tRecSql3!id
Debug.Print LBL & "-" & tRecSql4!id
if not tRecSql3.eof then tRecSql3.MoveNext
Next i
tRecSql4.MoveNext
Wend
Wend
#7
结贴吧,人呢在在在 在在d
#1
你的嵌套写的没错,在for i=1 to 3这层循环里更新数据就行了。
#2
可是问题是在第一个i=1里,tRecSql3数据就列举完毕了EOF了,等到i=2,tRecSql3就没数据了
#3
那你就要增加判断了哦。 如果eof了就跳出去,否则movenext
#4
该怎么写呢?不会啊
#5
While Not tRecSql4.EOF
While Not tRecSql3.EOF
For i = 1 To 3
LBL1 = tRecSql3!id
Debug.Print LBL & "-" & tRecSql4!id
tRecSql3.MoveNext
Next i
tRecSql4.MoveNext
Wend
Wend
#6
While Not tRecSql4.EOF
While Not tRecSql3.EOF
For i = 1 To 3
LBL1 = tRecSql3!id
Debug.Print LBL & "-" & tRecSql4!id
if not tRecSql3.eof then tRecSql3.MoveNext
Next i
tRecSql4.MoveNext
Wend
Wend
#7
结贴吧,人呢在在在 在在d