Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. select AlphaId, AlphaSubdivisionId, AlphaPlanTypeId, AlphaStartDate, AlphaPlan, AlphaPlanToday, AlphaFact, AlphaDailyFact, AlphaMonthName
  2.  
  3. , round((AlphaFact*100)/AlphaPlan,2) as AlphaTotalPercent, round((AlphaPlan-AlphaFact)/(day(eomonth(AlphaStartDate))-day(AlphaStartDate)),2) as AlphaPlanDaily,
  4. round(AlphaDailyFact*100/round((AlphaPlan-AlphaFact)/(day(eomonth(AlphaStartDate))-day(AlphaStartDate)),2),2 ) as AlphaDailyPercent
  5. , AlphaPlan-AlphaFact as AlphaLeftToPlan, round((AlphaPlan-AlphaFact)/(day(eomonth(AlphaStartDate))-day(AlphaStartDate)),2) - AlphaDailyFact as AlphaLeftToDailyPlan
  6. from (
  7.  
  8. select newid() as AlphaId, AlphaSubdivisionId,ALphaPlanTypeId, AlphaStartDate,ALphaPlan, AlphaPlan*cast((day(AlphaStartDate)*100)/day(eomonth(AlphaStartDate)) as float)/cast(100 as float) as AlphaPlanToday
  9. ,isNull(case
  10. when AlphaSubdivisionId='4691a98e-b4da-df11-9b2a-001d60e938c6' then
  11.  
  12. (select sum(AlphaTotalM2) from [order] as ord
  13. where month([date])=month(AlphaStartDate) and year([date])=year(AlphaStartDate) and
  14. statusId in ('40de86ee-274d-4098-9b92-9ebdcf83d4fc','c8742634-ea8b-46d9-ba71-1989b951772d'))
  15.  
  16.  
  17. when AlphaSubdivisionId!='4691a98e-b4da-df11-9b2a-001d60e938c6' then
  18.  
  19. (select sum(AlphaTotalM2) from [order] as ord
  20. where month([date])=month(AlphaStartDate) and year([date])=year(AlphaStartDate) and
  21. statusId in ('40de86ee-274d-4098-9b92-9ebdcf83d4fc','c8742634-ea8b-46d9-ba71-1989b951772d')
  22.  
  23. and (select count(Id) from AlphaAccountResponsible where AlphaAccountId=ord.AccountId and AlphaResponsibleId in (select Id from Contact where DepartmentId=pl.AlphaSubdivisionId))>0
  24.  
  25. )
  26.  
  27. end,0)
  28.  
  29. as AlphaFact
  30. ,isNull(case
  31. when AlphaSubdivisionId='4691a98e-b4da-df11-9b2a-001d60e938c6' then
  32.  
  33. (select sum(AlphaTotalM2) from [order] as ord
  34. where cast([date] as date) = cast(AlphaStartDate as date) and
  35. statusId in ('40de86ee-274d-4098-9b92-9ebdcf83d4fc','c8742634-ea8b-46d9-ba71-1989b951772d'))
  36.  
  37.  
  38. when AlphaSubdivisionId!='4691a98e-b4da-df11-9b2a-001d60e938c6' then
  39.  
  40. (select sum(AlphaTotalM2) from [order] as ord
  41. where cast([date] as date) = cast(AlphaStartDate as date) and
  42. statusId in ('40de86ee-274d-4098-9b92-9ebdcf83d4fc','c8742634-ea8b-46d9-ba71-1989b951772d')
  43.  
  44. and (select count(Id) from AlphaAccountResponsible where AlphaAccountId=ord.AccountId and AlphaResponsibleId in (select Id from Contact where DepartmentId=pl.AlphaSubdivisionId))>0
  45.  
  46. )
  47.  
  48. end, 0)
  49.  
  50. as AlphaDailyFact
  51. , datename(month,AlphaStartDate) as AlphaMonthName
  52. --,() as fact
  53.  
  54. from AlphaTotalMonthlyPlanForM2 as pl ) as t1
  55. where AlphaPlan!=0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement