你的语句可以改成
select a.name,id_card,b.sname,sfzh,a.bknbcode_id,b.leibie into shuju
from no07 a ,zuihoujieguo b
where a.name=b.sname
and len(b.sfzh)=15
and len(a.id_card)=15
and a.id_card=b.sfzh
and a.bknbcode_id=b.leibie
union
select a.name,id_card,b.sname,sfzh,a.bknbcode_id,b.leibie
from forums_ksbm a ,zuihoujieguo b
where a.name=b.sname
and
(
(
len(b.sfzh)=18
and len(a.id_card)=18
and a.id_card=b.sfzh
and a.bknbcode_id=b.leibie
)
or
(
(left(b.sfzh,6)=left(a.id_card,6)
and a.bknbcode_id=b.leibie)
and
(
(len(b.sfzh)=15 and len(a.id_card)=18 and substring(a.id_card,9,6)=substring(b.sfzh,7,6))
or
(len(a.id_card)=15 and len(b.sfzh)=18 and substring(b.sfzh,9,6)=substring(a.id_card,7,6))
)
)
)
不过为什么会出现相同的.你得看一下你的表中的数据是怎样的了.
select a.name,id_card,b.sname,sfzh,a.bknbcode_id,b.leibie into shuju
from no07 a ,zuihoujieguo b
where a.name=b.sname
and len(b.sfzh)=15
and len(a.id_card)=15
and a.id_card=b.sfzh
and a.bknbcode_id=b.leibie
union
select a.name,id_card,b.sname,sfzh,a.bknbcode_id,b.leibie
from forums_ksbm a ,zuihoujieguo b
where a.name=b.sname
and
(
(
len(b.sfzh)=18
and len(a.id_card)=18
and a.id_card=b.sfzh
and a.bknbcode_id=b.leibie
)
or
(
(left(b.sfzh,6)=left(a.id_card,6)
and a.bknbcode_id=b.leibie)
and
(
(len(b.sfzh)=15 and len(a.id_card)=18 and substring(a.id_card,9,6)=substring(b.sfzh,7,6))
or
(len(a.id_card)=15 and len(b.sfzh)=18 and substring(b.sfzh,9,6)=substring(a.id_card,7,6))
)
)
)
不过为什么会出现相同的.你得看一下你的表中的数据是怎样的了.
![](/skin/img/sigline.gif)
飘过~~