CNCEC_SUBQHSE_WUHUAN/DataBase/版本日志/已更新脚本/2021年度/SGGLDB_V2021-09-22-001.sql

119 lines
7.6 KiB
Transact-SQL

ALTER VIEW [dbo].[View_WBS_CostControlDetail]
AS
/********控制项明细********/
SELECT detail.CostControlDetailId,
detail.CostControlId,
detail.Months,
detail.StartDate,
detail.EndDate,
c.CostControlCode,
c.CostControlName,
c.WbsSetId,
c.ProjectId,
c.Unit, --单位
c.TotalNum, --合同工作量
CONVERT(FLOAT,(select sum(ISNULL(PlanNum,0)) from WBS_CostControlDetail where CostControlId=detail.CostControlId and Months<=detail.Months and StartDate is null)) as TotalPlanNum, --累计计划完成量
CONVERT(FLOAT,(select sum(ISNULL(PlanNum,0)) from WBS_CostControlDetail where CostControlId=detail.CostControlId and ((Months<detail.Months and StartDate is null) or (Months=detail.Months and StartDate<=detail.StartDate)))) as TotalWeekPlanNum, --累计周计划完成量
CONVERT(FLOAT,(select sum(ISNULL(ThisNum,0)) from WBS_CostControlDetail where CostControlId=detail.CostControlId and Months<=detail.Months)) as TotalThisNum, --累计完成量
CONVERT(FLOAT,(select sum(ISNULL(ThisNum,0)) from WBS_CostControlDetail where CostControlId=detail.CostControlId and Months<=detail.Months and StartDate<=detail.StartDate)) as TotalWeekThisNum, --累计周完成量
CONVERT(FLOAT,(select sum(ISNULL(d.PlanNum,0)) from WBS_CostControlDetail d
where d.CostControlId=detail.CostControlId and Months=detail.Months and StartDate is null)) as PlanNum, --本月计划完成量
CONVERT(FLOAT,ISNULL(detail.PlanNum,0)) as PlanWeekNum, --本周计划完成量
CONVERT(FLOAT,(select sum(ISNULL(d.ThisNum,0)) from WBS_CostControlDetail d
where d.CostControlId=detail.CostControlId and Months=detail.Months)) as ThisNum, --本月完成量
CONVERT(FLOAT,ISNULL(detail.ThisNum,0)) as ThisWeekNum, --本周完成量
c.RealPrice, --成本单价
c.PlanPrice, --控制预算单价
CONVERT(FLOAT,(select sum(ISNULL(d.PlanNum,0)*ISNULL(c1.PlanPrice,0)) from WBS_CostControlDetail d
LEFT JOIN WBS_CostControl AS c1 ON c1.CostControlId=d.CostControlId
where d.CostControlId=detail.CostControlId and Months=detail.Months and StartDate is null)) as ThisPlanValue, --本月计划完成预算
CONVERT(FLOAT,(select sum(ISNULL(d.PlanNum,0)*ISNULL(c1.PlanPrice,0)) from WBS_CostControlDetail d
LEFT JOIN WBS_CostControl AS c1 ON c1.CostControlId=d.CostControlId
where d.CostControlId=detail.CostControlId and Months=detail.Months and StartDate=detail.StartDate)) as ThisWeekPlanValue, --本周计划完成预算
CONVERT(FLOAT,(select sum(ISNULL(d.ThisNum,0)*ISNULL(c1.RealPrice,0)) from WBS_CostControlDetail d
LEFT JOIN WBS_CostControl AS c1 ON c1.CostControlId=d.CostControlId
where d.CostControlId=detail.CostControlId and Months=detail.Months)) as ThisRealCost, --本月实际成本
CONVERT(FLOAT,(select sum(ISNULL(d.ThisNum,0)*ISNULL(c1.RealPrice,0)) from WBS_CostControlDetail d
LEFT JOIN WBS_CostControl AS c1 ON c1.CostControlId=d.CostControlId
where d.CostControlId=detail.CostControlId and Months=detail.Months and StartDate=detail.StartDate)) as ThisWeekRealCost, --本周实际成本
CONVERT(FLOAT,(select sum(ISNULL(ThisNum,0)*ISNULL(c1.PlanPrice,0)) from WBS_CostControlDetail d
LEFT JOIN WBS_CostControl AS c1 ON c1.CostControlId=d.CostControlId
where d.CostControlId=detail.CostControlId and Months=detail.Months)) as ThisPlanCost, --本月完成预算
CONVERT(FLOAT,(select sum(ISNULL(ThisNum,0)*ISNULL(c1.PlanPrice,0)) from WBS_CostControlDetail d
LEFT JOIN WBS_CostControl AS c1 ON c1.CostControlId=d.CostControlId
where d.CostControlId=detail.CostControlId and Months=detail.Months and StartDate=detail.StartDate)) as ThisWeekPlanCost, --本周完成预算
CONVERT(FLOAT,(select sum(ISNULL(d.PlanNum,0)*ISNULL(c1.PlanPrice,0)) from WBS_CostControlDetail d
LEFT JOIN WBS_CostControl AS c1 ON c1.CostControlId=d.CostControlId
where d.CostControlId=detail.CostControlId and Months<=detail.Months and StartDate is null)) as TotalPlanValue, --累计计划完成预算
CONVERT(FLOAT,(select sum(ISNULL(d.PlanNum,0)*ISNULL(c1.PlanPrice,0)) from WBS_CostControlDetail d
LEFT JOIN WBS_CostControl AS c1 ON c1.CostControlId=d.CostControlId
where d.CostControlId=detail.CostControlId and ((Months<detail.Months and StartDate is null) or (Months=detail.Months and StartDate<=detail.StartDate)))) as TotalWeekPlanValue, --累计周计划完成预算
CONVERT(FLOAT,(select sum(ISNULL(d.ThisNum,0)*ISNULL(c1.RealPrice,0)) from WBS_CostControlDetail d
LEFT JOIN WBS_CostControl AS c1 ON c1.CostControlId=d.CostControlId
where d.CostControlId=detail.CostControlId and Months<=detail.Months)) as TotalRealCost, --累计完成成本
CONVERT(FLOAT,(select sum(ISNULL(d.ThisNum,0)*ISNULL(c1.RealPrice,0)) from WBS_CostControlDetail d
LEFT JOIN WBS_CostControl AS c1 ON c1.CostControlId=d.CostControlId
where d.CostControlId=detail.CostControlId and Months<=detail.Months and (StartDate<=detail.StartDate or StartDate is null))) as TotalWeekRealCost, --累计周完成成本
CONVERT(FLOAT,(select sum(ISNULL(ThisNum,0)*ISNULL(c1.PlanPrice,0)) from WBS_CostControlDetail d
LEFT JOIN WBS_CostControl AS c1 ON c1.CostControlId=d.CostControlId
where d.CostControlId=detail.CostControlId and Months<=detail.Months)) as TotalPlanCost, --累计完成预算
CONVERT(FLOAT,(select sum(ISNULL(ThisNum,0)*ISNULL(c1.PlanPrice,0)) from WBS_CostControlDetail d
LEFT JOIN WBS_CostControl AS c1 ON c1.CostControlId=d.CostControlId
where d.CostControlId=detail.CostControlId and Months<=detail.Months and (StartDate<=detail.StartDate or StartDate is null))) as TotalWeekPlanCost --累计周完成预算
FROM dbo.WBS_CostControlDetail AS detail
LEFT JOIN WBS_CostControl AS c ON c.CostControlId=detail.CostControlId
GO
ALTER VIEW [dbo].[View_WBS_CostControlParentDetail]
AS
/********控制项父级明细********/
SELECT detail.CostControlParentDetailId,
detail.ParentId,
detail.Months,
detail.StartDate,
detail.EndDate,
CONVERT(FLOAT,(select sum(ISNULL(ThisPlanValue,0)) from WBS_CostControlParentDetail
where ParentId=detail.ParentId and Months=detail.Months)) as ThisPlanValue, --本月计划完成预算
CONVERT(FLOAT,ISNULL(ThisPlanValue,0)) as ThisWeekPlanValue, --本周计划完成预算
CONVERT(FLOAT,(select sum(ISNULL(d.ThisRealCost,0)) from WBS_CostControlParentDetail d
where d.ParentId=detail.ParentId and Months=detail.Months)) as ThisRealCost, --本月实际成本
CONVERT(FLOAT,ISNULL(ThisRealCost,0)) as ThisWeekRealCost, --本周实际成本
CONVERT(FLOAT,(select sum(ISNULL(ThisPlanCost,0)) from WBS_CostControlParentDetail
where ParentId=detail.ParentId and Months=detail.Months)) as ThisPlanCost, --本月完成预算
CONVERT(FLOAT,ISNULL(ThisPlanCost,0)) as ThisWeekPlanCost, --本周完成预算
CONVERT(FLOAT,(select sum(ISNULL(ThisPlanValue,0)) from WBS_CostControlParentDetail
where ParentId=detail.ParentId and Months<=detail.Months)) as TotalPlanValue, --累计计划完成预算
CONVERT(FLOAT,(select sum(ISNULL(ThisPlanValue,0)) from WBS_CostControlParentDetail
where ParentId=detail.ParentId and Months<=detail.Months and (StartDate<=detail.StartDate or StartDate is null))) as TotalWeekPlanValue, --累计周计划完成预算
CONVERT(FLOAT,(select sum(ISNULL(d.ThisRealCost,0)) from WBS_CostControlParentDetail d
where d.ParentId=detail.ParentId and Months<=detail.Months)) as TotalRealCost, --累计完成成本
CONVERT(FLOAT,(select sum(ISNULL(d.ThisRealCost,0)) from WBS_CostControlParentDetail d
where d.ParentId=detail.ParentId and Months<=detail.Months and (StartDate<=detail.StartDate or StartDate is null))) as TotalWeekRealCost, --累计周完成成本
CONVERT(FLOAT,(select sum(ISNULL(ThisPlanCost,0)) from WBS_CostControlParentDetail
where ParentId=detail.ParentId and Months<=detail.Months)) as TotalPlanCost, --累计完成预算
CONVERT(FLOAT,(select sum(ISNULL(ThisPlanCost,0)) from WBS_CostControlParentDetail
where ParentId=detail.ParentId and Months<=detail.Months and (StartDate<=detail.StartDate or StartDate is null))) as TotalWeekPlanCost --累计周完成预算
FROM dbo.WBS_CostControlParentDetail AS detail
GO