Bom dia Pessoal,
Estou com um problema para finalizar uma consulta onde, quando executado a consulta e não encontrado nenhuma informação no período solicitado, tenho que trazer pelo menos o nome da conta.
Consulta,
WITH TMPESTONO (
NOME_IMPOSTO
,MES
,VALOR
)
AS (
SELECT 'ESTORNO SOBRE GREEN VILLE' AS NOME_IMPOSTO
,'F_' + SZN.ZN_ITEM AS FILFOR
,SUM((SZN.ZN_PRV * SZN.ZN_PRCAPL) / 100) AS TOTAL
FROM SZN010 SZN
WHERE SZN.D_E_L_E_T_ = ' '
AND SZN.ZN_ITEM IN (
'01'
,'16'
,'30'
,'40'
,'46'
,'51'
,'52'
,'60'
,'70'
,'72'
,'73'
,'80'
)
AND SZN.ZN_DATA BETWEEN '20220701'
AND '20220731'
AND SZN.ZN_DESC = ('GRENVILLE')
GROUP BY SZN.ZN_DESC
,SZN.ZN_ITEM
)
SELECT *
FROM (
SELECT NOME_IMPOSTO
,MES
,VALOR
FROM TMPESTONO
) AS PivotData
PIVOT(SUM(VALOR) FOR MES IN (
[F_16]
,[F_30]
,[F_40]
,[F_46]
,[F_51]
,[F_52]
,[F_60]
,[F_70]
,[F_72]
,[F_73]
,[TOTAL]
)) AS PivotTable2
ORDER BY 1