日期:2014-05-16  浏览次数:20524 次

sql优化,新员工,现在要优化一个项目的sql,就这点分了, 全给了,只希望有满意结果。

SELECT     FlyPM_Contract.CT_ID, FlyPM_Contract.CT_ConCode, FlyPM_Contract.CT_ConName, CommonParameter.CP_Name AS CT_ConStatus, 
                      CommonParameter_1.CP_Name AS CT_ConType, FlyPM_Contract.CT_ConMoney, FlyPM_Customer.sName AS CT_ConFirstSide, FlyPM_Contract.CT_ConFirstLinkMan, 
                      FlyPM_Contract.CT_ConFirstLinkTel, view_Department.PD_Name AS CT_ConMainDept, 
                      CommonParameter_2.CP_Name AS CT_ConClassify, FlyPM_Contract.CT_ConInvest, FlyPM_Contract.CT_ConScale, FlyPM_Contract.CT_ConPrjAddress, 
                      dbo.GetPhaseNameListCon(FlyPM_Contract.CT_ID) AS CT_ConPhase, FlyPM_Contract.CT_ConSignDate, dbo.GetConCreaterNameListCon(FlyPM_Contract.CT_ID) AS CT_ConCreater, 
                      FlyPM_Contract.CT_ConCreateDate, FlyPM_Contract.CT_ConFeeInfo, FlyPM_Contract.CT_ConSummary, FlyPM_Contract.CT_ConRemark, FlyPM_Contract.bFlag, 
                      FlyPM_Contract.sAttachID, ISNULL(GathingSumTotal.GathingTotal, 0) AS GathingTotal, ISNULL(GathingSumTotal.GathingTotal, 0) 
                      - ISNULL(CurYearGathintTal.GathingMoneyCurYear, 0) AS GathingMoneyHistoryYear, ISNULL(CurYearGathintTal.GathingMoneyCurYear, 0) AS GathingMoneyCurYear, 
                      FlyPM_Contract.CT_ConMoney - ISNULL(GathingSumTotal.GathingTotal, 0) AS ShengYu, 
                      FlyPM_Contract.CT_ConStartDate, FlyPM_Contract.CT_ConDemandDate, FlyPM_Contract.CT_ConFactDate, 
                      CASE WHEN (FlyPM_Contract.CT_ConMoney - ISNULL(GathingSumTotal.GathingTotal, 0)) 
                      > 0 THEN '<font color=red>合同欠款</font>' WHEN (FlyPM_Contract.CT_ConMoney - ISNULL(GathingSumTotal.GathingTotal, 0)) 
                      < 0 THEN '<font color=cyan>合同多收</font>' ELSE '<font color=green>收款完结</font>' END AS notice, view_AllUser1.PU_Name AS CT_ConPreson, 
                      dbo.GetCoDeptNameLis