select *
from SCG G
left join
FGYS S
ON G.ID=S.ID
left join
HUTS H
IF(LEN(H.vNAME)>0)
ON H.ID=S.ID
ELSE
ON H.AID=S.ID
END
红色部分报错,求解,谢谢
------解决方案--------------------
select *
from SCG G
left join
FGYS S
ON G.ID=S.ID
left join
HUTS H
ON ( ( LEN(H.vNAME)>0 and H.ID=S.ID) or (LEN(H.vNAME)<=0 and H.AID=S.ID) )
------解决方案--------------------
select *
from SCG G
left join FGYS S ON G.ID=S.ID
left join HUTS H on S.ID=case when LEN(H.vNAME)>0 then H.ID else H.AID end