吐血,求好方法。。left join 多次同个表
SELECT DATEDIFF(YEAR,a.Birthday,GETDATE()) Age,a.*,u.UnitType,u.UnitName,c1.CodeName SexName,c2.CodeName NativeName,c3.CodeName FolkName,
c4.CodeName ZuiGaoXueLiName,c5.CodeName SourceName,c6.CodeName yuandanweiOutlaycodeName,c7.CodeName FirstDutyCodeName,c8.CodeName PersonSortCodeName,
c9.CodeName HomeplaceName,c10.OrganName DepartmentName,c11.CodeName WeaveStateCodeName,c12.CodeName kaiserdomcodeName,c13.CodeName WeaveSortcodeName,
c14.CodeName outlaycodeName,c15.CodeName SecondDutyCodeName,c16.CodeName CadreSortName,c17.CodeName StudyCodeName,c18.CodeName WeaveSortcodeName,
FROM (
SELECT '0' Mark,* FROM A001A002
UNION ALL
SELECT '1' Mark,* FROM A021A002) a
LEFT JOIN Unit_Status u ON u.UnitID = a.UnitID
Left Join (Select Code,CodeName From Sys_Code Where CodeType='AX') c1 ON a.Sex=c1.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='AB') c2 ON a.Native=c2.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='AE') c3 ON a.Folk=c3.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='PH') c4 ON a.ZuiGaoXueLi=c4.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='YB') c5 ON a.Source=c5.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='AOutlay') c6 ON a.yuandanweiOutlaycode=c6.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='ADUTYOfO') c7 ON a.FirstDutyCode=c7.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='APersonSort') c8 ON a.PersonSortCode=c8.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='AB') c9 ON A.Homeplace=c9.Code
Left Join DepartInfo c10 ON A.DepartmentID=c10.UnitID
Left Join (Select Code,CodeName From Sys_Code Where CodeType='AWeaveState') c11 ON A.WeaveStateCode=c11.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='AT') c12 ON A.kaiserdomcode=c12.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='AWeave') c13 ON A.WeaveSortcode=c13.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='AOutlay') c14 ON A.outlaycode=c14.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='ADUTYOfF') c15 ON A.SecondDutyCode=c15.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='JF') c16 ON A.CadreSort=c16.Code
Left Join (Select Code,CodeName From Sys_Code Where CodeType='PH') c17 ON A.StudyCode=c17.Code