求大神帮我看一段代码,帮我看下问题出在哪里,有点多,要慢慢看
SELECT CASE WHEN GROUPING(tmp.quarter) = 0
AND GROUPING(s.Month) = 1
THEN CAST(tmp.quarter AS VARCHAR) + '季度总汇'
WHEN GROUPING(tmp.quarter) = 1
THEN CAST(s.YEAR AS VARCHAR) + '年合计'
ELSE CAST(s.Year AS VARCHAR) + '年' + CAST(s.Month AS VARCHAR)
+ '月'
END AS '时间' ,
ISNULL(SUM(s.Amount), 0) AS '计划销售金额' ,
( SELECT ISNULL(SUM(CASE WHEN Status LIKE '激活' THEN HtTotal
ELSE 0
END), 0)
FROM dbo.s_Contract
WHERE s.ProjGUID = ProjGUID
AND CAST(DATEPART(MM, QSDate) AS VARCHAR) = CAST(s.Month AS VARCHAR)
) AS '实际销售金额' ,
ISNULL(SUM(s.JHHKAmount), 0) AS '计划回款金额' ,
( SELECT ISNULL(SUM(Amount), 0)
FROM dbo.s_Getin ,
dbo.s_Trade ,
dbo.p_Room
WHERE dbo.s_Getin.SaleGUID = dbo.s_Trade.TradeGUID
AND dbo.s_Trade.RoomGUID = dbo.p_Room.RoomGUID
AND dbo.p_Room.ProjGUID = s.ProjGUID
AND dbo.s_Getin.Status IS NULL
AND DATEPART(MM, GetDate) = s.Month
&