EnVisageOnline/Main/Database/Scripts/20160624/01_Alter_Actual_Capacity_Vi...

62 lines
4.3 KiB
Transact-SQL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Use [EnVisage]
IF EXISTS(SELECT * FROM sys.views WHERE Name = N'VW_ActualCapacityByTeamsAdjusted')
BEGIN
DROP VIEW VW_ActualCapacityByTeamsAdjusted
PRINT 'VW_ActualCapacityByTeamsAdjusted dropped'
END
GO
IF EXISTS(SELECT * FROM sys.views WHERE Name = N'VW_ActualCapacityAdjusted')
BEGIN
DROP VIEW VW_ActualCapacityAdjusted
PRINT 'VW_ActualCapacityAdjusted dropped'
END
GO
IF EXISTS(SELECT * FROM sys.views WHERE Name = N'VW_ActualCapacityByTeamsDirect')
BEGIN
DROP VIEW VW_ActualCapacityByTeamsDirect
PRINT 'VW_ActualCapacityByTeamsDirect dropped'
END
GO
CREATE VIEW [dbo].[VW_ActualCapacityByTeamsDirect] AS
SELECT TeamId, ExpenditureCategoryId, WeekEndingDate,
ISNULL(SUM(Quantity), 0) as Quantity,
ISNULL(SUM(Cost), 0) as Cost,
ISNULL(COUNT(1), 0) as Resources
FROM VW_ActualCapacityDirect
GROUP BY TeamId, ExpenditureCategoryId, WeekEndingDate
GO
PRINT 'VW_ActualCapacityByTeamsDirect created'
GO
CREATE VIEW [dbo].[VW_ActualCapacityAdjusted] AS
SELECT ACD.PeopleResourceId, ACD.TeamId, ACD.ExpenditureCategoryId, ACD.WeekEndingDate,
ACD.Quantity as QuantityDirect, ACD.Cost as CostDirect,
ISNULL((ACD.Quantity * ISNULL(HA.AdjustmentKoeff, 1)), 0) as QuantityAdjusted,
ISNULL((ACD.Cost * ISNULL(HA.AdjustmentKoeff, 1)), 0) as CostAdjusted,
ISNULL(HA.AdjustmentKoeff, 1) as AdjustmentKoeff
FROM VW_ActualCapacityDirect ACD
LEFT JOIN VW_HolidayAllocation HA ON (HA.PeopleResourceId = ACD.PeopleResourceId) AND
(HA.ExpenditureCategoryId = ACD.ExpenditureCategoryId) AND
(HA.TeamId = ACD.TeamId) AND (HA.WeekEndingDate = ACD.WeekEndingDate)
GO
PRINT 'VW_ActualCapacityAdjusted created'
GO
CREATE VIEW [dbo].[VW_ActualCapacityByTeamsAdjusted] AS
SELECT TeamId, ExpenditureCategoryId, WeekEndingDate,
ISNULL(SUM(QuantityDirect), 0) as QuantityDirect,
ISNULL(SUM(CostDirect), 0) as CostDirect,
ISNULL(SUM(QuantityAdjusted), 0) as QuantityAdjusted,
ISNULL(SUM(CostAdjusted), 0) as CostAdjusted,
ISNULL(COUNT(1), 0) as ResourcesDirect,
ISNULL(SUM(AdjustmentKoeff), 0) as ResourcesAdjusted
FROM VW_ActualCapacityAdjusted
GROUP BY TeamId, ExpenditureCategoryId, WeekEndingDate
GO
PRINT 'VW_ActualCapacityByTeamsAdjusted created'
GO