CREATE TABLE [dbo].[WBS_MilePost]( [MilePostId] [nvarchar](50) NOT NULL, [ProjectId] [nvarchar](50) NULL, [CnProfessionId] [int] NULL, [MilePostName] [nvarchar](100) NULL, [PlanDate] [datetime] NULL, [RealDate] [datetime] NULL, [CompileMan] [nvarchar](50) NULL, [CompileDate] [datetime] NULL, [Remark] [nvarchar](200) NULL, CONSTRAINT [PK_WBS_MilePost] PRIMARY KEY CLUSTERED ( [MilePostId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO ALTER TABLE [dbo].[WBS_MilePost] WITH CHECK ADD CONSTRAINT [FK_WBS_MilePost_Base_Project] FOREIGN KEY([ProjectId]) REFERENCES [dbo].[Base_Project] ([ProjectId]) GO ALTER TABLE [dbo].[WBS_MilePost] CHECK CONSTRAINT [FK_WBS_MilePost_Base_Project] GO ALTER TABLE [dbo].[WBS_MilePost] WITH CHECK ADD CONSTRAINT [FK_WBS_MilePost_Sys_User] FOREIGN KEY([CompileMan]) REFERENCES [dbo].[Sys_User] ([UserId]) GO ALTER TABLE [dbo].[WBS_MilePost] CHECK CONSTRAINT [FK_WBS_MilePost_Sys_User] GO ALTER TABLE [dbo].[WBS_MilePost] WITH CHECK ADD CONSTRAINT [FK_WBS_MilePost_WBS_CnProfessionInit] FOREIGN KEY([CnProfessionId]) REFERENCES [dbo].[WBS_CnProfessionInit] ([CnProfessionId]) GO ALTER TABLE [dbo].[WBS_MilePost] CHECK CONSTRAINT [FK_WBS_MilePost_WBS_CnProfessionInit] GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_MilePost', @level2type=N'COLUMN',@level2name=N'MilePostId' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'项目Id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_MilePost', @level2type=N'COLUMN',@level2name=N'ProjectId' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'专业Id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_MilePost', @level2type=N'COLUMN',@level2name=N'CnProfessionId' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'里程碑名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_MilePost', @level2type=N'COLUMN',@level2name=N'MilePostName' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'计划完成日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_MilePost', @level2type=N'COLUMN',@level2name=N'PlanDate' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'实际完成日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_MilePost', @level2type=N'COLUMN',@level2name=N'RealDate' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'编制人' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_MilePost', @level2type=N'COLUMN',@level2name=N'CompileMan' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'编制日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_MilePost', @level2type=N'COLUMN',@level2name=N'CompileDate' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'备注' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_MilePost', @level2type=N'COLUMN',@level2name=N'Remark' GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'里程碑表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_MilePost' GO alter table [dbo].[WBS_CostControlDetail] add StartDate datetime null alter table [dbo].[WBS_CostControlDetail] add EndDate datetime null alter table [dbo].[WBS_CostControlDetailHistory] add StartDate datetime null alter table [dbo].[WBS_CostControlDetailHistory] add EndDate datetime null GO alter table [dbo].[WBS_CostControlParentDetail] add StartDate datetime null alter table [dbo].[WBS_CostControlParentDetail] add EndDate datetime null 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,(select sum(ISNULL(d.ThisRealCost,0)) from WBS_CostControlParentDetail d where d.ParentId=detail.ParentId and Months=detail.Months)) as ThisRealCost, --本月实际成本 CONVERT(FLOAT,(select sum(ISNULL(ThisPlanCost,0)) from WBS_CostControlParentDetail where ParentId=detail.ParentId and Months=detail.Months)) as ThisPlanCost, --本月完成预算 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(d.ThisRealCost,0)) from WBS_CostControlParentDetail d where d.ParentId=detail.ParentId and Months<=detail.Months)) as TotalRealCost, --累计完成成本 CONVERT(FLOAT,(select sum(ISNULL(ThisPlanCost,0)) from WBS_CostControlParentDetail where ParentId=detail.ParentId and Months<=detail.Months)) as TotalPlanCost --累计完成预算 FROM dbo.WBS_CostControlParentDetail AS detail GO 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(ThisNum,0)) from WBS_CostControlDetail where CostControlId=detail.CostControlId and Months<=detail.Months)) as TotalThisNum, --累计完成量 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,(select sum(ISNULL(d.ThisNum,0)) from WBS_CostControlDetail d where d.CostControlId=detail.CostControlId and Months=detail.Months)) as ThisNum, --本月完成量 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.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(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(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.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(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 --累计完成预算 FROM dbo.WBS_CostControlDetail AS detail LEFT JOIN WBS_CostControl AS c ON c.CostControlId=detail.CostControlId GO ALTER VIEW [dbo].[View_WBS_CostControlDetailStatistics] AS select InstallationId as Id,null as SupId ,InstallationName as Name,'Installation' as WBSType,null as OldCnProfessionId,null as OldUnitProjectCode,null as OldWbsSetCode, ProjectId from dbo.Project_Installation where SuperInstallationId is null Union select InstallationId as Id,SuperInstallationId as SupId ,InstallationName as Name,'Installation' as WBSType,null as OldCnProfessionId,null as OldUnitProjectCode,null as OldWbsSetCode, ProjectId from dbo.Project_Installation where SuperInstallationId is not null Union select CnProfessionId as Id , InstallationId as SupId,CnProfessionName as Name,'CnProfession' as WBSType,OldId as OldCnProfessionId,null as OldUnitProjectCode,null as OldWbsSetCode, ProjectId from dbo.WBS_CnProfession where IsApprove=1 Union all select UnitProjectId as Id, isnull(CnProfessionId,InstallationId) as SupId,UnitProjectName as Name,'UnitProject' as WBSType, (case when u.CnProfessionId is null then (select CnProfessionId from WBS_CnProfessionInit where CnProfessionName=(select InstallationName from Project_Installation where InstallationId=u.InstallationId)) else (select OldId from WBS_CnProfession c where c.CnProfessionId=u.CnProfessionId) end) as OldCnProfessionId,UnitProjectCode as OldUnitProjectCode,null as OldWbsSetCode, ProjectId from dbo.Wbs_UnitProject u where IsApprove=1 Union all select WbsSetId as id,UnitProjectId as SupId, WbsSetName as Name,'WbsSet' as WBSType, (case when w.CnProfessionId is null then (select CnProfessionId from WBS_CnProfessionInit where CnProfessionName=(select InstallationName from Project_Installation where InstallationId=w.InstallationId)) else (select OldId from WBS_CnProfession c where c.CnProfessionId=w.CnProfessionId) end) as OldCnProfessionId,(select UnitProjectCode from Wbs_UnitProject c where c.UnitProjectId=w.UnitProjectId) as OldUnitProjectCode, WbsSetCode as OldWbsSetCode, ProjectId from dbo.Wbs_WbsSet w where IsApprove=1 and SuperWbsSetId is null Union all select WbsSetId as id,SuperWbsSetId as SupId, WbsSetName as Name,'WbsSet' as WBSType, (case when w.CnProfessionId is null then (select CnProfessionId from WBS_CnProfessionInit where CnProfessionName=(select InstallationName from Project_Installation where InstallationId=w.InstallationId)) else (select OldId from WBS_CnProfession c where c.CnProfessionId=w.CnProfessionId) end) as OldCnProfessionId,(select UnitProjectCode from Wbs_UnitProject c where c.UnitProjectId=w.UnitProjectId) as OldUnitProjectCode, (select WbsSetCode from Wbs_WbsSet ws where ws.WbsSetId=w.SuperWbsSetId) as OldWbsSetCode, ProjectId from dbo.Wbs_WbsSet w where IsApprove=1 and SuperWbsSetId is not null Union all select c.CostControlId as id,c.WbsSetId as SupId,c.CostControlName as Name,'CostControl' as WBSType, (case when ws.CnProfessionId is null then (select CnProfessionId from WBS_CnProfessionInit where CnProfessionName=(select InstallationName from Project_Installation where InstallationId=ws.InstallationId)) else (select OldId from WBS_CnProfession cn where cn.CnProfessionId=(select top 1 CnProfessionId from Wbs_WbsSet w where w.WbsSetId=c.WbsSetId)) end) as OldCnProfessionId, (select UnitProjectCode from Wbs_UnitProject u where u.UnitProjectId=(select top 1 UnitProjectId from Wbs_WbsSet w where w.WbsSetId=c.WbsSetId)) as OldUnitProjectCode, (select WbsSetCode from Wbs_WbsSet u where u.WbsSetId=(select top 1 w.SuperWbsSetId from Wbs_WbsSet w where w.WbsSetId=c.WbsSetId)) as OldWbsSetCode, c.ProjectId from dbo.WBS_CostControl c left join dbo.Wbs_WbsSet ws on ws.WbsSetId=c.WbsSetId where c.TotalNum is not null GO