3
I am trying to execute a command in my sql, but always when I try it turns me an End of File error, I already looked line by line and nothing figured out, how can I solve this problem ?
DECLARE @anohref int
SET @anohref = YEAR(GETDATE())
DECLARE @pastanohref int
SET @pastanohref = YEAR(GETDATE()) - 1
SELECT SUM(total) total
FROM(
SELECT sum(WorkOrder) AS total from WorkOrder WHERE workType = '02' AND businessUnit = 'MM' and year(conclusionDate) = @anohref
UNION ALL
SELECT sum(WorkOrder) AS total from WorkOrder WHERE workType = 'CORRETIVA' AND businessUnit = 'MM' and year(conclusionDate) = @anohref
) s
UNION ALL
select sum(total) total
from (
select sum(workOrder) as total from workOrder where workType = '02' and year(workOrderDate)=2018
union all
select sum(workOrder) as total from workOrder where workType= 'corretiva' and year(workOrderDate)=2018
) s ;
WITH subresults AS
(
SELECT MES = MONTH(workOrderDate),
preventiva =
(SUM(CASE WHEN WorkType = '02'
AND workOrderDescription = 'preventiva' THEN 1.0 ELSE 0 END
)),
corretivas = (SUM(CASE WHEN workOrderDescription = 'CORRETIVA' THEN 1 ELSE 0 END)),
total = SUM(CASE WHEN WorkType = '02'
AND workOrderDescription = 'preventiva' THEN 1.0
ELSE 0 END + CASE WHEN workOrderDescription = 'CORRETIVA' THEN 1 ELSE 0 END
)
FROM WorkOrder WHERE
YEAR(workOrderDate) = @pastanohref
GROUP BY MONTH(workOrderDate)
)
Thanks man, I didn’t realize!
– Lucas Tadeu Egídio Arruda