Skip to Content
0

Error SWEI

Oct 31, 2017 at 07:47 PM

81

avatar image
Former Member

Buen día, espero alguien me pueda ayudar, les comento estoy presentando problemas con una consulta , cabe mencionar que estaba funcionando perfectamente y sin razón aparente dejo de hacerlo me marca este error:

"1). [Microsoft][SQL Server Native Client 11.0][SQL Server]Divide by zero error encountered. '' (SWEI)"

El código que estoy usando es el siguiente:

select distinct T0.absentry, T0.fiproject,T0.name,T0.cardcode, T0.cardname, T2.slpname,
CASE T0.STATUS 
when  'S' then 'Iniciado'
when 'P' then 'Pausado'
when 'T' then 'Detenido'
when 'F' then 'Finalizado'
when 'N' then 'Cancelado'
end as 'Estado',
T0.FINISHED '% de Completo',isnull(cast(T1.Overdue as numeric),0) 'Dias de Atraso',t1.TotalAR, t1.TotVarAR ,  t1.InvoicedAR, t1.OpenAmtAR, 


(select isnull(sum(doctotal),0)  from ORDR  where PROJECT =t0.FIPROJECT  and canceled = 'N') 'Total Proyecto c/ IVA',


(select (select isnull(sum(doctotal),0) from oinv where Project = t0.FIPROJECT and canceled = 'N') - (select isnull(sum(doctotal),0) from orin where Project=t0.FIPROJECT and canceled = 'N')) 'Total Facturado c/ IVA',


(select isnull(sum(doctotal),0) from orct  where PrjCode =  t0.FIPROJECT and canceled = 'N') 'Total Pagado Proyecto' 


,((select isnull(sum(doctotal),0) from orct  where PrjCode =  t0.FIPROJECT and canceled = 'N')*100)/(select isnull(sum(doctotal),0)  from ORDR  where PROJECT =t0.FIPROJECT  and canceled = 'N') '% Pagado'


,( select isnull(sum(doctotal),0) from oinv  where project=t0.FIPROJECT and canceled = 'N') -  ( select isnull(sum(doctotal),0) from orin t2 where project=t0.FIPROJECT and canceled = 'N') 
 - (select isnull(sum(doctotal),0) from orct t1 where PrjCode= t0.FIPROJECT and canceled = 'N')  'Total Deuda Proyecto'
 




 FROM OPMG T0 left join PMG8 T1 on t0.AbsEntry = T1.AbsEntry left join OSLP t2 on t0.EMPLOYEE=t2.SlpCode left join oinv t3 on t0.FIPROJECT=t3.Project left join orin t4 on t0.FIPROJECT=t3.Project
 where STATUS != 'N'
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
avatar image
Former Member Nov 01, 2017 at 12:50 PM
0

Hola Liliana, La consulta puede devolver un valor de 0 en la consulta secundaria que calcule% Pagado, y la base de datos no puede manejar la división 0.

Puede cambiar la consulta a esto:

select distinct T0.absentry, T0.fiproject,T0.name,T0.cardcode, T0.cardname, T2.slpname,
CASE T0.STATUS 
when  'S' then 'Iniciado'
when 'P' then 'Pausado'
when 'T' then 'Detenido'
when 'F' then 'Finalizado'
when 'N' then 'Cancelado'
end as 'Estado',
T0.FINISHED '% de Completo',isnull(cast(T1.Overdue as numeric),0) 'Dias de Atraso',t1.TotalAR, t1.TotVarAR ,  t1.InvoicedAR, t1.OpenAmtAR, 




(select isnull(sum(doctotal),0)  from ORDR  where PROJECT =t0.FIPROJECT  and canceled = 'N') 'Total Proyecto c/ IVA',




(select (select isnull(sum(doctotal),0) from oinv where Project = t0.FIPROJECT and canceled = 'N') - (select isnull(sum(doctotal),0) from orin where Project=t0.FIPROJECT and canceled = 'N')) 'Total Facturado c/ IVA',




(select isnull(sum(doctotal),0) from orct  where PrjCode =  t0.FIPROJECT and canceled = 'N') 'Total Pagado Proyecto' 




,((select isnull(sum(doctotal),0) from orct  where PrjCode =  t0.FIPROJECT and canceled = 'N')*100)/(select isnull(sum(doctotal),1)  from ORDR  where PROJECT =t0.FIPROJECT  and canceled = 'N') '% Pagado'




,( select isnull(sum(doctotal),0) from oinv  where project=t0.FIPROJECT and canceled = 'N') -  ( select isnull(sum(doctotal),0) from orin t2 where project=t0.FIPROJECT and canceled = 'N') 
 - (select isnull(sum(doctotal),0) from orct t1 where PrjCode= t0.FIPROJECT and canceled = 'N')  'Total Deuda Proyecto'
 








 FROM OPMG T0 left join PMG8 T1 on t0.AbsEntry = T1.AbsEntry left join OSLP t2 on t0.EMPLOYEE=t2.SlpCode left join oinv t3 on t0.FIPROJECT=t3.Project left join orin t4 on t0.FIPROJECT=t3.Project
 where STATUS != 'N'

Espero que sea de ayuda Saludos

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Muchas gracias, problema resuelto!!

Saludos :D..

0