Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   SQL (https://www.clubdelphi.com/foros/forumdisplay.php?f=6)
-   -   Como Ubicar registros cuya diferencia sea diferente a cero (https://www.clubdelphi.com/foros/showthread.php?t=73062)

oscarac 29-03-2011 22:16:18

Como Ubicar registros cuya diferencia sea diferente a cero
 
buenas tardes

tengo la siguiente informacion (ejemplo)
Cita:

200901... 01... 0001... D... 10.00
200901... 01... 0001... H... 10.00
200901... 01... 0002... D... 100.00
200901... 01... 0002... D... 101.00
me gustaria hacer una consulta que me muestre lo siguiente

Cita:

Periodo Libro voucher. Debe Haber.. Diferencia
200901... 01... 0002...100.00....101.00....1.00
yo he hecho esto..
Código SQL [-]
 
Select Periodo, Libro, Voucher, 
SUM (iif (MOV.DH = 'D', MOV.n_IMP, 0.00)) AS DEBE,  
SUM (Iif (MOV.DH = 'H', MOV.n_IMP, 0.00)) AS HABER ,
SUM (iif (MOV.DH = 'D', MOV.n_IMP, 0.00)) - SUM (Iif (MOV.DH = 'H', MOV.n_IMP, 0.00)) AS Dif
from  tblMovimientoContable MOV 
group by Periodo, Libro, Voucher

pero me muestra "todas" los vouchers (incluso los que no tienen diferencia).. me gustaria solo ubicar aquellos que tienen diferencia

Cita:

Periodo Libro voucher. Debe Haber.. Diferencia
200901... 01... 0001... 10.00.....10.00.....0.00
200901... 01... 0002...100.00....101.00....1.00
espero haberme hecho entender:)

maeyanes 29-03-2011 22:20:05

Hola...

Puedes agregar un having así:

Código SQL [-]
Select Periodo, Libro, Voucher, 
SUM (iif (MOV.DH = 'D', MOV.n_IMP, 0.00)) AS DEBE,  
SUM (Iif (MOV.DH = 'H', MOV.n_IMP, 0.00)) AS HABER ,
SUM (iif (MOV.DH = 'D', MOV.n_IMP, 0.00)) - SUM (Iif (MOV.DH = 'H', MOV.n_IMP, 0.00)) AS Dif
from  tblMovimientoContable MOV 
group by Periodo, Libro, Voucher
having SUM (iif (MOV.DH = 'D', MOV.n_IMP, 0.00)) - SUM (Iif (MOV.DH = 'H', MOV.n_IMP, 0.00)) > 0


Saludos...

oscarac 29-03-2011 22:22:53

funciona...
gracias


La franja horaria es GMT +2. Ahora son las 05:37:44.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi