日期:2014-05-18  浏览次数:20528 次

带条件的join方式
SQL code
select isnull(sod.csocode,sod2.csocode) csocode,isnull(sod.iRowNo,sod2.iRowNo) irowno,isnull(so.ccusname,so2.ccusname) ccusname,inv.cinvname,。。
from rdrecord10 rd inner join rdrecords10 rds on rd.id=rds.id and rd.cvouchtype='10'
inner join inventory inv on inv.bsale=1 and rds.cinvcode=inv.cinvcode
left join so_sodetails sod on rds.isodid=cast(sod.isosid as varchar(20)) --如果rds.isodid存在就用这条关联
left join so_sodetails sod2 on rds.cmocode=sod2.csocode and sod2.cinvcode=rds.cinvcode --如果不存在就用这关联
where isnull(sod.csocode,sod2.csocode) is not null
group by sod.csocode,sod2.csocode,sod.irowno,sod2.irowno,so.ccusname,so2.ccusname,inv.cinvname,inv.cinvstd


这两条如何能并成一条,求解

------解决方案--------------------
探讨

现在就是isodid与cmosode都存在时,就会有重复记录,因为两次left join都存在