rp

asked on

# sql server conditional query in sum

i have a query like this:

select sum(credito)-SUM(Debito) as Saldo from movimentostesouraria where idconta=1 and DataDocumento < '2010-11-20'

group by idconta

If sum(credito)-SUM(Debito) is positive i need put result value in Credito column, otherwise in Debito column (not is saldo)

select sum(credito)-SUM(Debito) as Saldo from movimentostesouraria where idconta=1 and DataDocumento < '2010-11-20'

group by idconta

If sum(credito)-SUM(Debito) is positive i need put result value in Credito column, otherwise in Debito column (not is saldo)

ASKER CERTIFIED SOLUTION

membership

Create an account to see this answer

Signing up is free. No credit card required.