1
Guys, how to add the query below as a subconsulta.
Consultation with WITH:
WITH dias AS(
SELECT CAST('2017-06-26' AS DATE) AS dia
UNION ALL
SELECT DATEADD(DAY, 1, d.dia)
FROM dias d
WHERE d.dia < '2017-06-30'
)
SELECT CONVERT(VARCHAR, d.dia, 103) AS data_cancelado,
COUNT(s.solid) AS cancelados
FROM dias d
LEFT JOIN solicitacao s ON CONVERT(DATE, s.soldatafechamento, 103) = d.dia
AND s.proid = 4
AND s.solestagioid = 110
GROUP BY d.dia
OPTION (MAXRECURSION 0);
Another Query, where this is to put the query from above, because another column will be generated with the query above.
select
CONVERT(DATE,S.SolData,103) [DATA],
COUNT (S.SolID) [Abertos]
from Solicitacao S
where S.ProID = 4 and S.SolData between '26-06-2017' and '30-06-2017' and S.SolTipID = 35
GROUP BY CONVERT(DATE,S.SolData,103)
It’s to go out that way
Data Abertos Cancelados
26-06-2017 0 2
27-06-2017 2 1
28-06-2017 5 0
29-06-2017 4 0
30-06-2017 0 4
How are Welding and Welding columns declared? If declared as
datetime
, they contain only the date or contain date and time?– José Diz
A same line can have Weld and Weld Machining in the emission period, have Solestagioid = 110 and have Soltipid = 35? // For example: you may have an open request on 27/6 and cancelled on 29/6?
– José Diz