Avoid getting out 0.00 in SQL server query

0

I have this query and send a 0.00 data and I do not want to be killed

my query:

select
Descuento = isnull((
                SELECT sum(x.Valor)
                FROM Cuenta x
                where
                x.IdSer between 25 and 39
                and x.Valor != 0.00
                and x.IdA = cc.IdA),0)

from Cuenta cc

group by
cc.IdCur,
cc.IdAl

    
asked by Rodrigo Rodriguez 01.11.2017 в 16:27
source

1 answer

1

As already mentioned in the comments, you give little information and the query seems more complex than it should be. Specifically for what you are asking, you should bear in mind that you are using the grouping function sum () . In your query, if you have two records where x.Value is for example 5 and the other is -5, the final sum of these values will give you a zero. As you understand with your question, you want to avoid the results that give you zero, not the individual records. So what you could use is a clause having :

SELECT sum(x.Valor)
FROM Cuenta x
where
x.IdSer between 25 and 39    
and x.IdA = cc.IdA
group by
cc.IdCur, cc.IdAl
having sum(x.Valor) != 0
    
answered by 01.11.2017 в 18:03