El coalesce va fuera. Antes ya lo había probado, pero me daba error porque
después hay que poner dos paréntesis y yo ponía uno.
La selección del group by tiene que ser idéntica. Coalesce incluido.
Gracias.
Declare @cursor2 scroll cursor for
select alarti, arnomb, sum(alcanp), Coalesce
((select sum(fetpaq) from arcfil/fetipa
where fetemp=alempr and fetalb=alnalb and fetcli=alclie
and fetexp=aldalb and fetart=alarti
group by fetart), 0)
from arcfil/ealbcl join arcfil/fartic on alarti=arcodi
where alempr=:empres and alclie=:@client and aldalb=:Data_entry
And alnalb=:@albara and alsitu in('A', 'F')
group by alnalb, alarti, arnomb, Coalesce
((select sum(fetpaq) from arcfil/fetipa
where fetemp=alempr and fetalb=alnalb and fetcli=alclie
and fetexp=aldalb and fetart=alarti
group by fetart), 0)
For read only;
De: "Alberto Martinez" <[email protected]>
Para: "forum.help400" <[email protected]>
Fecha: 06/11/2019 10:09
Asunto: ** Newsletter ** Problemas con el Null y coalesce
Enviado por: [email protected]
Buenos dias.
A ver si alguien me puede dar una pista:
Tengo una selección con dos tablas que se pide la suma de un campo de la
primera y la suma de un campo de la segunda.
en la segunda no tiene por qué existir. ésta misma selección, como es uno
de los campos que muestro y tiene el SUM dentro, me obliga a ponerla en el
group by
Yo eso lo resolvería con:
select alarti, arnomb, sum(alcanp),
(select (coalesce(sum(fetpaq), 0))
from arcfil.fetipa
where fetemp=alempr and fetalb=alnalb and fetcli=alclie
and fetexp=aldalb and fetart=alarti group by fetart)
from arcfil.ealbcl join arcfil.fartic on alarti=arcodi
where alempr=10 and alclie=3958 and aldalb=20191106
And alnalb=21603 and alsitu in('A', 'F')
group by alnalb, alarti, arnomb,
(select (coalesce(sum(fetpaq), 0))
from arcfil.fetipa
where fetemp=alempr and fetalb=alnalb and
fetcli=alclie
and fetexp=aldalb and fetart=alarti group by
fetart)
For read only;
Y de hecho, con un script así me funciona, pero se para el coalesce por el
forro y me devuelve NULOS donde no encuentra nada, y yo quiero ceros,
porque en el programa me daría error.
Alguien ve algo que yo no veo?
Gracias ____________________________________________________
Únete a Recursos AS400, nuestra Comunidad ( http://bit.ly/db68dd )
Forum.Help400 © Publicaciones Help400, S.L.
____________________________________________________
Únete a Recursos AS400, nuestra Comunidad ( http://bit.ly/db68dd )
Forum.Help400 © Publicaciones Help400, S.L.