I have this follow query; the objective is to filter this query by day.
I will use this same query, but now a month. How to do?
WITH DATAS(DATA_CALC) AS(
SELECT DATE(#prompt('DataIni')#) AS DATA_CALC FROM SYSIBM.SYSDUMMY1
UNION ALL
SELECT DATA_CALC + 1 DAY FROM DATAS WHERE DATA_CALC < DATE(#prompt('DataFim')#)
)
/* ABERTOS */
SELECT COUNT(*) AS QUANTIDADE, 'ABERTOS' AS TIPO, 1 AS NUM_LINHA, DATE(TRUNC(SOL.DATA_ABERTURA_SOLICITACAO)) AS DATA
FROM VW_SOLICITACAO_DETALHE SOL
INNER JOIN SOLICITACAO SOL_TAB ON (SOL_TAB.ID_SOLICITACAO = SOL.ID_SOLICITACAO)
WHERE SOL.COD_TIPO_SERVICO IN ('MC','OP','SA')
AND SOL_TAB.ID_AREA_COLABORADOR IN (#promptmany('IDArea')#)
AND TRUNC(SOL.DATA_ABERTURA_SOLICITACAO) >= to_date('2014-11-18','YYYY-MM-DD')
AND TRUNC(SOL.DATA_ABERTURA_SOLICITACAO) <= #prompt('DataFim')#
AND ('TODOS' IN (#promptmany('Sistema')#) OR SOL.COD_PRODUTO IN (#promptmany('Sistema')#))
AND DSC_SITUACAO_SOLICITACAO NOT IN ('Desenvolvimento Cancelado')
AND SOL.COD_SOLICITACAO NOT LIKE 'SA%'
GROUP BY TRUNC(SOL.DATA_ABERTURA_SOLICITACAO)
The best solution is to create a Time dimension that includes days and months. This is not easy to plug into Dynamic SQL like you are using above, so you can instead try a work around.
A report studio work around would be to create year and month columns, and group on them:
For year: extract(year, [datefieldhere])
For month: extract(month, [datefieldhere])