alter table [dbo].[Wbs_UnitProjectInit] add SortIndex int null
GO
alter table [dbo].[Project_Installation] add IsEnd bit null
GO


CREATE TABLE [dbo].[WBS_CostControlInit](
	[CostControlInitId] [nvarchar](50) NOT NULL,
	[CostControlInitCode] [nvarchar](50) NOT NULL,
	[CostControlInitName] [nvarchar](100) NULL,
	[Unit] [nvarchar](50) NULL,
 CONSTRAINT [PK_WBS_CostControlInit_1] PRIMARY KEY CLUSTERED 
(
	[CostControlInitId] 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

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlInit', @level2type=N'COLUMN',@level2name=N'CostControlInitId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlInit', @level2type=N'COLUMN',@level2name=N'CostControlInitCode'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlInit', @level2type=N'COLUMN',@level2name=N'CostControlInitName'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'单位' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlInit', @level2type=N'COLUMN',@level2name=N'Unit'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'费控项初始化表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlInit'
GO




CREATE TABLE [dbo].[WBS_WbsSetMatchCostControlInit](
	[WbsSetMatchCostControlInitId] [nvarchar](50) NOT NULL,
	[WbsSetCode] [nvarchar](50) NULL,
	[CostControlInitCode] [nvarchar](50) NULL,
 CONSTRAINT [PK_WBS_WbsSetMatchCostControlInit] PRIMARY KEY CLUSTERED 
(
	[WbsSetMatchCostControlInitId] 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_WbsSetMatchCostControlInit]  WITH CHECK ADD  CONSTRAINT [FK_WBS_WbsSetMatchCostControlInit_WBS_WbsSetInit] FOREIGN KEY([WbsSetCode])
REFERENCES [dbo].[WBS_WbsSetInit] ([WbsSetCode])
GO

ALTER TABLE [dbo].[WBS_WbsSetMatchCostControlInit] CHECK CONSTRAINT [FK_WBS_WbsSetMatchCostControlInit_WBS_WbsSetInit]
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WbsSetMatchCostControlInit', @level2type=N'COLUMN',@level2name=N'WbsSetMatchCostControlInitId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'工作包编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WbsSetMatchCostControlInit', @level2type=N'COLUMN',@level2name=N'WbsSetCode'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'费控项编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WbsSetMatchCostControlInit', @level2type=N'COLUMN',@level2name=N'CostControlInitCode'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'工作包匹配费控项初始表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WbsSetMatchCostControlInit'
GO




CREATE TABLE [dbo].[WBS_WbsSetMatchCostControl](
	[WbsSetMatchCostControlId] [nvarchar](50) NOT NULL,
	[WbsSetId] [nvarchar](50) NULL,
	[CostControlCode] [nvarchar](50) NULL,
 CONSTRAINT [PK_WBS_WbsSetMatchCostControl] PRIMARY KEY CLUSTERED 
(
	[WbsSetMatchCostControlId] 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

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WbsSetMatchCostControl', @level2type=N'COLUMN',@level2name=N'WbsSetMatchCostControlId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'费用清单对应关系表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_WbsSetMatchCostControl'
GO








CREATE TABLE [dbo].[WBS_CostControl](
	[CostControlId] [nvarchar](50) NOT NULL,
	[ProjectId] [nvarchar](50) NULL,
	[WbsSetId] [nvarchar](50) NULL,
	[CostControlCode] [nvarchar](50) NULL,
	[CostControlName] [nvarchar](100) NULL,
	[Unit] [nvarchar](50) NULL,
	[TotalNum] [decimal](18, 2) NULL,
	[RealPrice] [decimal](18, 2) NULL,
	[PlanPrice] [decimal](18, 2) NULL,
 CONSTRAINT [PK_WBS_CostControl] PRIMARY KEY CLUSTERED 
(
	[CostControlId] 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_CostControl]  WITH CHECK ADD  CONSTRAINT [FK_WBS_CostControl_Base_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Base_Project] ([ProjectId])
GO

ALTER TABLE [dbo].[WBS_CostControl] CHECK CONSTRAINT [FK_WBS_CostControl_Base_Project]
GO

ALTER TABLE [dbo].[WBS_CostControl]  WITH CHECK ADD  CONSTRAINT [FK_WBS_CostControl_Wbs_WbsSet] FOREIGN KEY([WbsSetId])
REFERENCES [dbo].[Wbs_WbsSet] ([WbsSetId])
GO

ALTER TABLE [dbo].[WBS_CostControl] CHECK CONSTRAINT [FK_WBS_CostControl_Wbs_WbsSet]
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControl', @level2type=N'COLUMN',@level2name=N'CostControlId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'项目Id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControl', @level2type=N'COLUMN',@level2name=N'ProjectId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControl', @level2type=N'COLUMN',@level2name=N'CostControlCode'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControl', @level2type=N'COLUMN',@level2name=N'CostControlName'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'单位' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControl', @level2type=N'COLUMN',@level2name=N'Unit'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'合同工作量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControl', @level2type=N'COLUMN',@level2name=N'TotalNum'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'成本单价' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControl', @level2type=N'COLUMN',@level2name=N'RealPrice'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'控制预算单价' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControl', @level2type=N'COLUMN',@level2name=N'PlanPrice'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'费控项表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControl'
GO








alter table [dbo].[WBS_CnProfession] add IsSelected bit null
alter table [dbo].[WBS_CnProfession] add IsApprove bit null
GO






CREATE TABLE [dbo].[WBS_CostControlDetail](
	[CostControlDetailId] [nvarchar](50) NOT NULL,
	[CostControlId] [nvarchar](50) NULL,
	[Months] [datetime] NULL,
	[PlanNum] [decimal](9, 2) NULL,
	[ThisNum] [decimal](9, 2) NULL,
 CONSTRAINT [PK_WBS_CostControlDetail] PRIMARY KEY CLUSTERED 
(
	[CostControlDetailId] 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_CostControlDetail]  WITH CHECK ADD  CONSTRAINT [FK_WBS_CostControlDetail_WBS_CostControl] FOREIGN KEY([CostControlId])
REFERENCES [dbo].[WBS_CostControl] ([CostControlId])
GO

ALTER TABLE [dbo].[WBS_CostControlDetail] CHECK CONSTRAINT [FK_WBS_CostControlDetail_WBS_CostControl]
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlDetail', @level2type=N'COLUMN',@level2name=N'CostControlDetailId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'外键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlDetail', @level2type=N'COLUMN',@level2name=N'CostControlId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'月份' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlDetail', @level2type=N'COLUMN',@level2name=N'Months'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本月计划量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlDetail', @level2type=N'COLUMN',@level2name=N'PlanNum'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本月完成量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlDetail', @level2type=N'COLUMN',@level2name=N'ThisNum'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'费控项明细表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlDetail'
GO














CREATE VIEW [dbo].[View_WBS_CostControlDetail]
AS
/********控制项明细********/
SELECT detail.CostControlDetailId, 
detail.CostControlId, 
detail.Months, 
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)) as TotalPlanNum,  --累计计划完成量
CONVERT(FLOAT,(select sum(ISNULL(ThisNum,0)) from WBS_CostControlDetail where CostControlId=detail.CostControlId and Months<=detail.Months)) as TotalThisNum,  --累计完成量
detail.PlanNum,  --本月计划完成量
detail.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)) 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)) 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


























CREATE 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,(select OldId from WBS_CnProfession c where c.CnProfessionId=u.CnProfessionId) 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,(select OldId from WBS_CnProfession c where c.CnProfessionId=w.CnProfessionId) 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,(select OldId from WBS_CnProfession c where c.CnProfessionId=w.CnProfessionId) 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,(select OldId from WBS_CnProfession c where c.CnProfessionId=(select top 1  CnProfessionId from Wbs_WbsSet w where w.WbsSetId=WbsSetId)) 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 where c.TotalNum is not null 







GO






























CREATE TABLE [dbo].[WBS_CostControlParentDetail](
	[CostControlParentDetailId] [nvarchar](50) NOT NULL,
	[ParentId] [nvarchar](50) NULL,
	[Months] [datetime] NULL,
	[ThisPlanValue] [decimal](18, 2) NULL,
	[ThisRealCost] [decimal](18, 2) NULL,
	[ThisPlanCost] [decimal](18, 2) NULL,
 CONSTRAINT [PK_WBS_CostControlParentDetail] PRIMARY KEY CLUSTERED 
(
	[CostControlParentDetailId] 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

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlParentDetail', @level2type=N'COLUMN',@level2name=N'CostControlParentDetailId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'外键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlParentDetail', @level2type=N'COLUMN',@level2name=N'ParentId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'月份' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlParentDetail', @level2type=N'COLUMN',@level2name=N'Months'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本月计划完成预算' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlParentDetail', @level2type=N'COLUMN',@level2name=N'ThisPlanValue'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本月实际成本' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlParentDetail', @level2type=N'COLUMN',@level2name=N'ThisRealCost'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本月完成预算' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlParentDetail', @level2type=N'COLUMN',@level2name=N'ThisPlanCost'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'费控项父级明细表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlParentDetail'
GO







CREATE VIEW [dbo].[View_WBS_CostControlParentDetail]
AS
/********控制项父级明细********/
SELECT detail.CostControlParentDetailId, 
detail.ParentId, 
detail.Months, 
detail.ThisPlanValue,  --本月计划完成预算
detail.ThisRealCost,  --本月实际成本
detail.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




CREATE TABLE [dbo].[WBS_CostControlDetailHistory](
	[CostControlDetailHistoryId] [nvarchar](50) NOT NULL,
	[CostControlId] [nvarchar](50) NULL,
	[Months] [datetime] NULL,
	[PlanNum] [decimal](9, 2) NULL,
	[VersionNum] [int] NULL,
 CONSTRAINT [PK_WBS_CostControlDetailHistory] PRIMARY KEY CLUSTERED 
(
	[CostControlDetailHistoryId] 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_CostControlDetailHistory]  WITH CHECK ADD  CONSTRAINT [FK_WBS_CostControlDetailHistory_WBS_CostControl] FOREIGN KEY([CostControlId])
REFERENCES [dbo].[WBS_CostControl] ([CostControlId])
GO

ALTER TABLE [dbo].[WBS_CostControlDetailHistory] CHECK CONSTRAINT [FK_WBS_CostControlDetailHistory_WBS_CostControl]
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlDetailHistory', @level2type=N'COLUMN',@level2name=N'CostControlDetailHistoryId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'费控项Id' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlDetailHistory', @level2type=N'COLUMN',@level2name=N'CostControlId'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'月份' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlDetailHistory', @level2type=N'COLUMN',@level2name=N'Months'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本月计划量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlDetailHistory', @level2type=N'COLUMN',@level2name=N'PlanNum'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'版本' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlDetailHistory', @level2type=N'COLUMN',@level2name=N'VersionNum'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'费控项明细历史记录表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'WBS_CostControlDetailHistory'
GO


