两表结构相同,相同字段不同内容对比

数据表问题 | 2015-04-01 00:30:35 | 阅读 712 次 | 评论(0)


* 该代码的前提是表结构相同,字段顺序相同,记录数相同,两表关键字段内容相同(同样适用关键字段内容不正确的情况,前提是记录顺序相同,这时用RECNO()作为索引关键字)
clear
create cursor tt (a1 c(10),a2 c(10),a3 c(10))
insert into tt values ("0001","abcd","aa")
insert into tt values ("0002","abcd","ab")
insert into tt values ("0003","abcd","ac")
insert into tt values ("0005","abc","aa")
insert into tt values ("0006","abc1d","2aa")
insert into tt values ("0004","abcd","ad")
index on a1 tag xx
create cursor tt1 (a1 c(10),a2 c(10),a3 c(10))
insert into tt1 values ("0001","abcd","aa")
insert into tt1 values ("0002","a3bcd","a1b")
insert into tt1 values ("0003","abcd","ac")
insert into tt1 values ("0004","ab5cd","ad")
insert into tt1 values ("0005","abc8","aa")
insert into tt1 values ("0006","abc1d","2aa")
set relation to a1 into tt
scan
    * 如果当记录数很多,且字段数也很多的情况下,可以用下面 <A段代码>,否则直接用 <B段代码>
    * A段代码
    scatter name ott
    select tt
    scatter name ott1
    if compobj(ott,ott1)=.t.
        loop
    endif 
    * B段代码
    for lnI=2 to 3
        if evaluate("tt1."+field(lnI))!=evaluate("tt."+field(lnI))
            * 字段内容不同的比较结果
            ?recno("tt1"),field(lnI,"TT1"),evaluate("tt1."+field(lnI)),evaluate("tt."+field(lnI))
        endif 
    endfor
endscan

* 因为没有测试数据,不知道是两段代码都用效率高,还是直接使用 B段代码 效率高,欢迎大家测试,并将测试结果留言。谢谢大家了!


文章评论,共0条
游客请输入验证码
浏览234485次
最新评论
  • cstdio:ooooooo
  • sdta:从VFP入手也不错
  • yuanhouwen:尊敬的sdta大神:作为一个编程外行,看到你关于操控EXCEL的编程程序我觉得特别神奇,想向你...