Jump to content


Photo

[RESUELTO] Restar Columnas


  • Please log in to reply
1 reply to this topic

#1 look

look

    Advanced Member

  • Miembros
  • PipPipPip
  • 418 posts
  • LocationLa Ceiba-Atlantida-Honduras

Posted 20 May 2011 - 01:58 PM

Hola , tengo la siguiente consulta.

select a.no_fact,b.descr, a.clv_doc , a.fech_aplic, a.fech_venc, c.abrev , a.importe ,
coalesce((select sum(importe)as Abono from cuentas f , conceptos g where g.tipo = 'C' and f.tipo_mov = g.num_cpto and f.no_fact = a.no_fact),0)as Cargos,
coalesce((select sum(importe)as Abono from cuentas f , conceptos g where g.tipo = 'A' and f.tipo_mov = g.num_cpto and f.no_fact = a.no_fact),0)as Abonos
from cuentas a , conceptos b , moned01 c
where b.tipo = 'C' and a.num_moned = c.num_moned and a.tipo_mov = b.num_cpto and b.clv_clie = :clv_clie


[img height=55 width=400]http://imageshack.us/m/860/170/query.png[/img]


con esta consulta consulto los cargos y abonos por cliente de mi tabla de cuentas (cuentas) , la tabla conceptos contiene los conceptos de cuentas por cobrar ...
lo que quiero hacer es restar la columna de cargos con los abonos para determinar el saldo del documento, pero no me sale 
¿me pueden hechar una mano?.
  • 0

#2 look

look

    Advanced Member

  • Miembros
  • PipPipPip
  • 418 posts
  • LocationLa Ceiba-Atlantida-Honduras

Posted 20 May 2011 - 02:08 PM

Hola , ya lo solucione,....



select a.no_fact,b.descr, a.clv_doc , a.fech_aplic, a.fech_venc, c.abrev , a.importe ,
coalesce(coalesce((select sum(importe)as Abono from cuentas f , conceptos g where g.tipo = 'C' and f.tipo_mov = g.num_cpto and f.no_fact = a.no_fact),0)-
coalesce((select sum(importe)as Abono from cuentas f , conceptos g where g.tipo = 'A' and f.tipo_mov = g.num_cpto and f.no_fact = a.no_fact),0),0)as Saldo
from cuentas a , conceptos b , moned01 c
where b.tipo = 'C' and a.num_moned = c.num_moned and a.tipo_mov = b.num_cpto


  • 0




IP.Board spam blocked by CleanTalk.