1、写一个自定义函数:
function GetVal(ID as long) as boolean
dim rs1 as new adodb.recordset,rs2 as new adodb.recordset
dim i as long
dim ssql as string
dim B as boolean
ssql="select * from 表A where ID=" & ID
rs1.open ssql,currentproject.connection,adopenkeyset,adlockoptimistic
rs2.open "表B",currentproject.connection,adopenkeyset,adlockoptimistic
B=false
for i=1 to rs2.recordcount
if instr(rs1("A1").value,rs2("B1").value)>0 then
B=true
exit for
end if
rs2.movenext
next
rs2.movefirst
for i=1 to rs2.recordcount
if rs1("A2").value=rs2("B2") then
B=false
exit for
end if
rs2.movenext
next
GetVal=B
rs1.close
rs2.close
end function
2、在查询中调用函数
select * from 表A where GetVal(ID)=-1
3、由于要反复在B表中查找,可能查询执行的时间会比较长。