select *
from A
inner join B on A.ID=B.ID
where 1=1
--如果参数a有值,则查询A.A1=a的数据并且A表有数据,B表没数据的所有数据
and (a is null or (A.A1=a and A.ID is not null and B.ID is null))
--如果参数b有值,则查询B.B1=B的数据并且A表没数据,B表有数据的所有数据
and (b is null or (B.B1=b and A.ID is null and B.ID is not null))
--如果参数c有值,则查询B.B1=c的数据并且A表没数据,B表有数据的所有数据
and (c is null or (B.B1=c and A.ID is null and B.ID is not null))
select A.A1, B.B1 from A left join B on A.A1 = B.B1 where (A1 = a) or ((B1 = b) or (B1 = c))
是这个意思吧!