119 lines
		
	
	
		
			7.6 KiB
		
	
	
	
		
			MySQL
		
	
	
	
		
		
			
		
	
	
			119 lines
		
	
	
		
			7.6 KiB
		
	
	
	
		
			MySQL
		
	
	
	
|  | 
 | |||
|  | ALTER VIEW [dbo].[View_WBS_CostControlDetail]
 | |||
|  | AS
 | |||
|  | /********<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ********/
 | |||
|  | SELECT detail.CostControlDetailId, 
 | |||
|  | detail.CostControlId, 
 | |||
|  | detail.Months, 
 | |||
|  | detail.StartDate,
 | |||
|  | detail.EndDate,
 | |||
|  | c.CostControlCode, 
 | |||
|  | c.CostControlName,
 | |||
|  | c.WbsSetId, 
 | |||
|  | c.ProjectId,
 | |||
|  | c.Unit,   --<EFBFBD><EFBFBD>λ
 | |||
|  | c.TotalNum,   --<EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | CONVERT(FLOAT,(select sum(ISNULL(PlanNum,0)) from WBS_CostControlDetail where CostControlId=detail.CostControlId and Months<=detail.Months and StartDate is null)) as TotalPlanNum,  --<EFBFBD>ۼƼƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | 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,  --<EFBFBD>ۼ<EFBFBD><EFBFBD>ܼƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | CONVERT(FLOAT,(select sum(ISNULL(ThisNum,0)) from WBS_CostControlDetail where CostControlId=detail.CostControlId and Months<=detail.Months)) as TotalThisNum,  --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | CONVERT(FLOAT,(select sum(ISNULL(ThisNum,0)) from WBS_CostControlDetail where CostControlId=detail.CostControlId and Months<=detail.Months and StartDate<=detail.StartDate)) as TotalWeekThisNum,  --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | 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,  --<EFBFBD><EFBFBD><EFBFBD>¼ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  |  CONVERT(FLOAT,ISNULL(detail.PlanNum,0)) as PlanWeekNum,  --<EFBFBD><EFBFBD><EFBFBD>ܼƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | CONVERT(FLOAT,(select sum(ISNULL(d.ThisNum,0)) from WBS_CostControlDetail d
 | |||
|  |  where d.CostControlId=detail.CostControlId and Months=detail.Months)) as ThisNum,  --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  |  CONVERT(FLOAT,ISNULL(detail.ThisNum,0)) as ThisWeekNum,  --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | c.RealPrice,    --<EFBFBD>ɱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | |||
|  | c.PlanPrice,   --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD>㵥<EFBFBD><EFBFBD>
 | |||
|  | 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,  --<EFBFBD><EFBFBD><EFBFBD>¼ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | 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,  --<EFBFBD><EFBFBD><EFBFBD>ܼƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | 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,  --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʳɱ<EFBFBD>
 | |||
|  | 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,  --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʳɱ<EFBFBD>
 | |||
|  | 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,  --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | 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,  --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | 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,  --<EFBFBD>ۼƼƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | 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,  --<EFBFBD>ۼ<EFBFBD><EFBFBD>ܼƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | 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,  --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɳɱ<EFBFBD>
 | |||
|  | 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,  --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɳɱ<EFBFBD>
 | |||
|  | 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,  --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | 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  --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | 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
 | |||
|  | /********<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ********/
 | |||
|  | 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,    --<EFBFBD><EFBFBD><EFBFBD>¼ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | CONVERT(FLOAT,ISNULL(ThisPlanValue,0)) as ThisWeekPlanValue,    --<EFBFBD><EFBFBD><EFBFBD>ܼƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | CONVERT(FLOAT,(select sum(ISNULL(d.ThisRealCost,0)) from WBS_CostControlParentDetail d
 | |||
|  | where d.ParentId=detail.ParentId and Months=detail.Months)) as ThisRealCost,  --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʳɱ<EFBFBD> 
 | |||
|  | CONVERT(FLOAT,ISNULL(ThisRealCost,0)) as ThisWeekRealCost,  --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʳɱ<EFBFBD> 
 | |||
|  | CONVERT(FLOAT,(select sum(ISNULL(ThisPlanCost,0)) from WBS_CostControlParentDetail 
 | |||
|  | where ParentId=detail.ParentId and Months=detail.Months)) as ThisPlanCost,  --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | CONVERT(FLOAT,ISNULL(ThisPlanCost,0)) as ThisWeekPlanCost,  --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | CONVERT(FLOAT,(select sum(ISNULL(ThisPlanValue,0)) from WBS_CostControlParentDetail 
 | |||
|  | where ParentId=detail.ParentId and Months<=detail.Months)) as TotalPlanValue,  --<EFBFBD>ۼƼƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | 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,  --<EFBFBD>ۼ<EFBFBD><EFBFBD>ܼƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | CONVERT(FLOAT,(select sum(ISNULL(d.ThisRealCost,0)) from WBS_CostControlParentDetail d
 | |||
|  | where d.ParentId=detail.ParentId and Months<=detail.Months)) as TotalRealCost,  --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɳɱ<EFBFBD>
 | |||
|  | 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,  --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɳɱ<EFBFBD>
 | |||
|  | CONVERT(FLOAT,(select sum(ISNULL(ThisPlanCost,0)) from WBS_CostControlParentDetail 
 | |||
|  | where ParentId=detail.ParentId and Months<=detail.Months)) as TotalPlanCost,  --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | 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  --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><EFBFBD>
 | |||
|  | FROM dbo.WBS_CostControlParentDetail AS detail
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | GO
 | |||
|  | 
 | |||
|  | 
 |