Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select AlphaId, AlphaSubdivisionId, AlphaPlanTypeId, AlphaStartDate, AlphaPlan, AlphaPlanToday, AlphaFact, AlphaDailyFact, AlphaMonthName
- , round((AlphaFact*100)/AlphaPlan,2) as AlphaTotalPercent, round((AlphaPlan-AlphaFact)/(day(eomonth(AlphaStartDate))-day(AlphaStartDate)),2) as AlphaPlanDaily,
- round(AlphaDailyFact*100/round((AlphaPlan-AlphaFact)/(day(eomonth(AlphaStartDate))-day(AlphaStartDate)),2),2 ) as AlphaDailyPercent
- , AlphaPlan-AlphaFact as AlphaLeftToPlan, round((AlphaPlan-AlphaFact)/(day(eomonth(AlphaStartDate))-day(AlphaStartDate)),2) - AlphaDailyFact as AlphaLeftToDailyPlan
- from (
- select newid() as AlphaId, AlphaSubdivisionId,ALphaPlanTypeId, AlphaStartDate,ALphaPlan, AlphaPlan*cast((day(AlphaStartDate)*100)/day(eomonth(AlphaStartDate)) as float)/cast(100 as float) as AlphaPlanToday
- ,isNull(case
- when AlphaSubdivisionId='4691a98e-b4da-df11-9b2a-001d60e938c6' then
- (select sum(AlphaTotalM2) from [order] as ord
- where month([date])=month(AlphaStartDate) and year([date])=year(AlphaStartDate) and
- statusId in ('40de86ee-274d-4098-9b92-9ebdcf83d4fc','c8742634-ea8b-46d9-ba71-1989b951772d'))
- when AlphaSubdivisionId!='4691a98e-b4da-df11-9b2a-001d60e938c6' then
- (select sum(AlphaTotalM2) from [order] as ord
- where month([date])=month(AlphaStartDate) and year([date])=year(AlphaStartDate) and
- statusId in ('40de86ee-274d-4098-9b92-9ebdcf83d4fc','c8742634-ea8b-46d9-ba71-1989b951772d')
- and (select count(Id) from AlphaAccountResponsible where AlphaAccountId=ord.AccountId and AlphaResponsibleId in (select Id from Contact where DepartmentId=pl.AlphaSubdivisionId))>0
- )
- end,0)
- as AlphaFact
- ,isNull(case
- when AlphaSubdivisionId='4691a98e-b4da-df11-9b2a-001d60e938c6' then
- (select sum(AlphaTotalM2) from [order] as ord
- where cast([date] as date) = cast(AlphaStartDate as date) and
- statusId in ('40de86ee-274d-4098-9b92-9ebdcf83d4fc','c8742634-ea8b-46d9-ba71-1989b951772d'))
- when AlphaSubdivisionId!='4691a98e-b4da-df11-9b2a-001d60e938c6' then
- (select sum(AlphaTotalM2) from [order] as ord
- where cast([date] as date) = cast(AlphaStartDate as date) and
- statusId in ('40de86ee-274d-4098-9b92-9ebdcf83d4fc','c8742634-ea8b-46d9-ba71-1989b951772d')
- and (select count(Id) from AlphaAccountResponsible where AlphaAccountId=ord.AccountId and AlphaResponsibleId in (select Id from Contact where DepartmentId=pl.AlphaSubdivisionId))>0
- )
- end, 0)
- as AlphaDailyFact
- , datename(month,AlphaStartDate) as AlphaMonthName
- --,() as fact
- from AlphaTotalMonthlyPlanForM2 as pl ) as t1
- where AlphaPlan!=0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement