Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   SQL (https://www.clubdelphi.com/foros/forumdisplay.php?f=6)
-   -   Eliminar registros de un query (https://www.clubdelphi.com/foros/showthread.php?t=73077)

oscarac 30-03-2011 16:32:23

Eliminar registros de un query
 
buenos dias...

me gustaria que alguien me ilumine en este tema... les cuento

tengo un query que me hace una simple suma

Código SQL [-]
select M.Periodo, M.Libro, M.Voucher, M.FechaVoucher,  
SUM(iif (M.DH = 'D', M.n_IMP, 0.00 )) AS DEBEMN,  
SUM(iif (M.DH = 'H', M.n_IMP, 0.00 )) AS HABERMN,  
(SUM(iif (M.DH = 'D', M.n_IMP, 0.00 )) - SUM(iif (M.DH = 'H', M.n_IMP, 0.00 )) AS DIFMN,  
SUM(iif (M.DH = 'D', M.u_IMP, 0.00 )) AS DEBEME,  
SUM(iif (M.DH = 'H', M.u_IMP, 0.00 )) AS HABERME ,
SUM(iif (M.DH = 'D', M.u_IMP, 0.00 )) - SUM(iif (M.DH = 'H', M.u_IMP, 0.00 )) AS DIFME
from tblmovimientocontable M  
Group by M.Periodo, M.Libro, M.Voucher, M.FechaVoucher 
order by M.Periodo, M.Libro, M.Voucher'


por algun motivo desconocido:confused: me muestra la siguiente informacion

Cita:

Periodo...Libro....Voucher....DebeMn... HaberMn.... DIFMn...............................DebeMe... HaberMe.... DIFMe...
200408....01........0002.........100.00......100.00....-1.4775425154752E-10........33.50.....33.50......-1.74622981477E-10
:S

en la base de Datos (tanto en Access como en Sql Server) he truncado el campo n_imp y el u_imp

Código SQL [-]
 
Update tblmovimientocontable Set n_imp = Round(n_imp,2)
Update tblmovimientocontable Set u_imp = Round(u_imp,2)

si los importes del Debe y el Haber son Iguales... porque esa diferencia?


si fuera por algun Ghost in the machine.. me gustaria "barrer" el query y eliminar aquellos registros que el debe sea igual al haber
gracias

gatosoft 30-03-2011 16:54:45

hola OscarC,

No te asustes, los valores que estas obteniendo: 1.4775425154752E-10, son realemente un cero, pero que por alguna razón de estructura de datos del compilador al hacer la suma o resta de valores de punto flotante, te entrgea esta diferencia...


Intenta no redondear/truncar los valores originales, sino el resultado de la suma en la consulta, asi:

Código SQL [-]
round((SUM(iif (M.DH = 'D', M.n_IMP, 0.00 )) - SUM(iif (M.DH = 'H', M.n_IMP, 0.00 )),2) AS DIFMN,  

round(SUM(iif (M.DH = 'D', M.u_IMP, 0.00 )) - SUM(iif (M.DH = 'H', M.u_IMP, 0.00 )),2) AS DIFME

espero te sirva

oscarac 30-03-2011 17:06:01

ok..
esto me ayudo mucho....
la cuestion ahora es que solo me muestre los que tienen diferencia

oscarac 30-03-2011 17:09:48

Resuelto
 
lo resolvi de esta manera....

Código SQL [-]
select M.Periodo, M.Libro, M.Voucher, M.FechaVoucher,  
SUM(iif (M.DH = 'D', M.n_IMP, 0.00 )) AS DEBEMN,  
SUM(iif (M.DH = 'H', M.n_IMP, 0.00 )) AS HABERMN,  
ROUND(SUM(iif (M.DH = 'D', M.n_IMP, 0.00 )) -  SUM(iif (M.DH = 'H', M.n_IMP, 0.00 ))) AS DIFMN,  
SUM(iif (M.DH = 'D', M.u_IMP, 0.00 )) AS DEBEME,  
SUM(iif (M.DH = 'H', M.u_IMP, 0.00 )) AS HABERME,  
ROUND(SUM(iif (M.DH = 'D', M.u_IMP, 0.00 )) -  SUM(iif (M.DH = 'H', M.u_IMP, 0.00 ))) AS DIFME 
from tblmovimientocontable M  
Group by M.Periodo, M.Libro, M.Voucher, M.FechaVoucher  
Having (
ROUND(SUM(iif (M.DH = 'D', M.n_IMP, 0.00 )) -  SUM(iif (M.DH = 'H', M.n_IMP, 0.00 ))) <> 0 or
ROUND(SUM(iif (M.DH = 'D', M.u_IMP, 0.00 )) -  SUM(iif (M.DH = 'H', M.u_IMP, 0.00 ))) <> 0 )
order by M.Periodo, M.Libro, M.Voucher


algo larguita la instruccion para algo tan sencillo..

se agradece


La franja horaria es GMT +2. Ahora son las 14:04:51.

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