CREATE TABLE [dbo].[FY_BUDGET_W] (
[FY_BUDGET_ID] [bigint] IDENTITY (1, 1) NOT NULL ,
[FK_BUDGET_ID] [bigint] NULL ,
[FY_BUDGET_STATUS] [nvarchar] (50) NULL ,
[FK_FISCAL_YEAR_ID] [bigint] NULL ,
[FK_EMPLOYEE$SUBMITOR_ID] [bigint] NULL ,
[UPDATE_REASON] [nvarchar] (255) NULL ,
[SUBMIT_DATE] [datetime] NULL ,
[FK_EMPLOYEE$INSPECTOR_ID] [bigint] NULL ,
[COMMENT] [nvarchar] (255) NULL ,
[INSPECT_DATE] [datetime] NULL
) ON [PRIMARY]
ALTER TABLE dbo.BUDGET ADD RECORD_FY_ID bigint NULL,
RECORD_BUDGET_STATUS nvarchar(50) NULL;
ALTER TABLE dbo.BUDGET ADD CONSTRAINT DF_BUDGET_RECORD_BUDGET_STATUS
DEFAULT 'DRAFT' FOR RECORD_BUDGET_STATUS;UPDATE BUDGET
SET RECORD_FY_ID = 0, RECORD_BUDGET_STATUS = 'DRAFT';
EFFORT_TRACE_ID:BudgetId_EffortEstimationId ( ProjectId_EffortEstimationId) :
ALTER TABLE EFFORT_ESTIMATION ADD [EFFORT_TRACE_ID] [nvarchar] (50) NULL ;
Update EFFORT_ESTIMATION set EFFORT_TRACE_ID=str(FK_BUDGET_ID)+'_'+str(EFFORT_ESTIMATION_ID);
EXPENSE_TRACE_ID:BudgetId_EffortEstimationId ( ProjectId_EffortEstimationId) :
ALTER TABLE EXPENSE_ESTIMATION ADD [EXPENSE_TRACE_ID] [nvarchar] (50) NULL ;
Update EXPENSE_ESTIMATION set EXPENSE_TRACE_ID=str(FK_BUDGET_ID)+'_'+str(ESTIMATION_ID);
ALTER TABLE dbo.BUDGET ADD SrcBudgetId bigint NULL;
declare @budgetIdmax int,@curBudgetId int,@FYbudgetStatus varchar(20),@processCount int;
select @budgetIdmax=max(budget_id) from budget;
set @curBudgetId=1;
while @curBudgetId0)
begin
INSERT INTO FY_BUDGET_W (FK_FISCAL_YEAR_ID,fk_budget_id,FY_BUDGET_STATUS)
(
select ee.fk_fiscalyear_id,b.BUDGET_ID,b.record_budget_status from
(select distinct fk_fiscalyear_id,fk_budget_id from effort_estimation where fk_budget_id=@curBudgetId ) ee
cross join
(SELECT * FROM BUDGET WHERE BUDGET_ID=@curBudgetId) b
) ;
end
set @curBudgetId=@curBudgetId+1;
end
declare @newBudgetIdMax int,@eeCount int,@SrcBudId bigint;
select @newBudgetIdMax=max(budget_id) from budget;
set @curBudgetId=@budgetIdmax+1;
while @curBudgetId0)
begin
Insert into Effort_estimation (TOPIC, MONTH_10, MONTH_11, MONTH_12, MONTH_1, MONTH_2, MONTH_3,
MONTH_4, MONTH_5, MONTH_6, MONTH_7, MONTH_8, MONTH_9,
FK_FISCALYEAR_ID, FK_BUDGET_ID, FK_DIVISION_ID, FK_WORKPACKAGE_ID,
INITIAL_TOTAL_MANMONTH, IS_ALIGNED, EFFORT_TRACE_ID)( SELECT TOPIC, MONTH_10, MONTH_11, MONTH_12, MONTH_1, MONTH_2, MONTH_3,
MONTH_4, MONTH_5, MONTH_6, MONTH_7, MONTH_8, MONTH_9,
FK_FISCALYEAR_ID, @curBudgetId, FK_DIVISION_ID, FK_WORKPACKAGE_ID,
INITIAL_TOTAL_MANMONTH, IS_ALIGNED, EFFORT_TRACE_ID
FROM EFFORT_ESTIMATION where fk_budget_id=@SrcBudId)
end
select @eeCount=count(*) from Expense_estimation where fk_budget_id=@curBudgetId;
if(@eeCount>0)
begin
insert into EXPENSE_ESTIMATION(TOPIC, MONTH_10, MONTH_11, MONTH_12, MONTH_1, MONTH_2, MONTH_3,
MONTH_4, MONTH_5, MONTH_6, MONTH_7, MONTH_8, MONTH_9,
FK_FISCALYEAR_ID, FK_BUDGET_ID, FK_COSTTYPE_ID, INIT_TOTAL_COST,EXPENSE_TRACE_ID)
(SELECT TOPIC, MONTH_10, MONTH_11, MONTH_12, MONTH_1, MONTH_2, MONTH_3,
MONTH_4, MONTH_5, MONTH_6, MONTH_7, MONTH_8, MONTH_9,
FK_FISCALYEAR_ID, @curBudgetId, FK_COSTTYPE_ID, INIT_TOTAL_COST,EXPENSE_TRACE_ID
FROM EXPENSE_ESTIMATION where fk_budget_id=@SrcBudId)
end
INSERT INTO FY_BUDGET_W (FK_FISCAL_YEAR_ID,fk_budget_id,FY_BUDGET_STATUS)
(
select ee.fk_fiscalyear_id,b.BUDGET_ID,b.record_budget_status from
(select distinct fk_fiscalyear_id,fk_budget_id from effort_estimation where fk_budget_id=@curBudgetId ) ee
cross join
(SELECT * FROM BUDGET WHERE BUDGET_ID=@curBudgetId) b
) ;
set @curBudgetId=@curBudgetId+1;
end