Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.63 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(getdate()))-day(getdate())),2) as AlphaPlanDaily,
  4. round(AlphaDailyFact*100/round((AlphaPlan-AlphaFact)/(day(eomonth(getdate()))-day(getdate())),2),2 ) as AlphaDailyPercent
  5. , AlphaPlan-AlphaFact as AlphaLeftToPlan, round((AlphaPlan-AlphaFact)/(day(eomonth(getdate()))-day(getdate())),2) - AlphaDailyFact as AlphaLeftToDailyPlan
  6. from (
  7.  
  8. select newid() as AlphaId,  AlphaSubdivisionId,ALphaPlanTypeId, AlphaStartDate,ALphaPlan, AlphaPlan*cast((day(getdate())*100)/day(eomonth(getdate())) 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(getdate()) and year([date])=year(getdate()) 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(getdate()) and year([date])=year(getdate()) 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(getdate() 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(getdate() 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