1
In this query, I have some stores that have not identified sale. Bringing the result as null. This impacts on the field of percentage and total. How could I make null fields to be interpreted as 0 and I can do my query calculations?
select ti.Loja as Loja,ti.NomeLoja as 'Nome Loja', ti.QtdTransacaoIdent as
'Identificado',
tni.QtdTransacaoNaoIdent as 'Não Identificado',
SUM(QtdTransacaoIdent)+ SUM(QtdTransacaoNaoIdent)as Total,
CONVERT(VARCHAR(50),
cast(QtdTransacaoIdent as money)/cast(QtdTransacaoIdent+ QtdTransacaoNaoIdent as money)*100)+' %' AS '% Engajamento'
from #temp_ident ti
left join #temp_n_ident tni on tni.loja = ti.loja
group by ti.Loja,ti.NomeLoja, ti.QtdTransacaoIdent,tni.QtdTransacaoNaoIdent
order by Loja,
CONVERT(VARCHAR(50),
cast(QtdTransacaoIdent as money)/cast(QtdTransacaoIdent+ QtdTransacaoNaoIdent as money)*100)
desc
Use the COALESCE function to consider zero where you have NULL.
– anonimo