Pb avec un SUM + CASE
Résolu
JsuisNul
Messages postés
125
Date d'inscription
Statut
Membre
Dernière intervention
-
baladur13 Messages postés 47807 Date d'inscription Statut Modérateur Dernière intervention -
baladur13 Messages postés 47807 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour,
J'ai une fonction dans laquelle je voudrais calculer plusieurs totaux avec des conditions.
Voici ma requête :
CURSOR liste_elements (startstring varchar) IS
SELECT societe,etabli,matric,nudosp,identite,SUM(MONSAL + MONPAT) SOMME1, SUM(KFB2) SOMME2 FROM
(
SELECT CASE
WHEN a.etabli like '955%' THEN a.etabli
WHEN a.etabli like '956%' THEN a.etabli
ELSE substr(a.etabli,1,3)
END SOCIETE,a.etabli,a.matric,a.nudosp,
RTRIM(c.nomuse)||' '||RTRIM(c.prenom) IDENTITE,
CASE
WHEN SUBSTR(a.perpai,3) < 201305 and b.codrub in ('FKE','FKJ')
THEN -25*b.monsal
WHEN SUBSTR(a.perpai,3) > 201305 and b.codrub in ('FKE','FKJ')
THEN 25*b.monsal
END MONSAL,
CASE
WHEN SUBSTR(a.perpai,3) < 201305 and b.codrub in ('FKE','FKJ')
THEN -25*b.monpat
WHEN SUBSTR(a.perpai,3) > 201305 and b.codrub in ('FKE','FKJ')
THEN 25*b.monpat
END MONPAT,
CASE
WHEN b.codrub ='FKB'
THEN - 25*b.monsal
ELSE 0
END AS KFB2
FROM zx37 a, zx8k b, zx0m d, zy00 c
WHERE a.nudoss=b.nudoss and a.nudoss=d.nudoss AND a.matric=c.matcle
AND a.typaie = 'F'
AND b.perpai = startstring
AND b.codrub in ('FKE','FKJ','FKB')
AND d.natcon not in ('SE','EP','E2')
AND a.matric =3002457
)
GROUP BY societe,etabli,matric,nudosp,identite
ORDER BY societe,etabli,matric,nudosp,identite;
voici les données à totaliser en table :
COD MONSAL MONPAT
--- ---------- ----------
FKB 690 0
FKE 0 -80
Voici mon résultat :
COLUMN_VALUE
--------------------------------------------------------------------------------
"=""100""";"=""100001 """;"=""3002457 """;5;nom prenom;2000;19250
"=""100""";Total = 100001 ;;;;2000;19250;1
La premiere somme à 2000 est bonne.
Dans la deuxieme je devrais retrouver 17250 au lieu des 19250 (19250 correspondant à la somme (690+ 80) *25).
j'ai l'impression que ma condition "WHEN b.codrub ='FKB'' n'est pas prise en compte.
Quelqu'un aurait une idée ?
Merci d'avance.
J'ai une fonction dans laquelle je voudrais calculer plusieurs totaux avec des conditions.
Voici ma requête :
CURSOR liste_elements (startstring varchar) IS
SELECT societe,etabli,matric,nudosp,identite,SUM(MONSAL + MONPAT) SOMME1, SUM(KFB2) SOMME2 FROM
(
SELECT CASE
WHEN a.etabli like '955%' THEN a.etabli
WHEN a.etabli like '956%' THEN a.etabli
ELSE substr(a.etabli,1,3)
END SOCIETE,a.etabli,a.matric,a.nudosp,
RTRIM(c.nomuse)||' '||RTRIM(c.prenom) IDENTITE,
CASE
WHEN SUBSTR(a.perpai,3) < 201305 and b.codrub in ('FKE','FKJ')
THEN -25*b.monsal
WHEN SUBSTR(a.perpai,3) > 201305 and b.codrub in ('FKE','FKJ')
THEN 25*b.monsal
END MONSAL,
CASE
WHEN SUBSTR(a.perpai,3) < 201305 and b.codrub in ('FKE','FKJ')
THEN -25*b.monpat
WHEN SUBSTR(a.perpai,3) > 201305 and b.codrub in ('FKE','FKJ')
THEN 25*b.monpat
END MONPAT,
CASE
WHEN b.codrub ='FKB'
THEN - 25*b.monsal
ELSE 0
END AS KFB2
FROM zx37 a, zx8k b, zx0m d, zy00 c
WHERE a.nudoss=b.nudoss and a.nudoss=d.nudoss AND a.matric=c.matcle
AND a.typaie = 'F'
AND b.perpai = startstring
AND b.codrub in ('FKE','FKJ','FKB')
AND d.natcon not in ('SE','EP','E2')
AND a.matric =3002457
)
GROUP BY societe,etabli,matric,nudosp,identite
ORDER BY societe,etabli,matric,nudosp,identite;
voici les données à totaliser en table :
COD MONSAL MONPAT
--- ---------- ----------
FKB 690 0
FKE 0 -80
Voici mon résultat :
COLUMN_VALUE
--------------------------------------------------------------------------------
"=""100""";"=""100001 """;"=""3002457 """;5;nom prenom;2000;19250
"=""100""";Total = 100001 ;;;;2000;19250;1
La premiere somme à 2000 est bonne.
Dans la deuxieme je devrais retrouver 17250 au lieu des 19250 (19250 correspondant à la somme (690+ 80) *25).
j'ai l'impression que ma condition "WHEN b.codrub ='FKB'' n'est pas prise en compte.
Quelqu'un aurait une idée ?
Merci d'avance.
A voir également:
- Pb avec un SUM + CASE
- Aller à la ligne dans une case excel - Guide
- Excel case choix multiple - Guide
- Supprimer case à cocher excel ✓ - Forum Excel
- Case à cocher excel - Forum MacOS
- Supprimer des cases à cocher (Excel 2003) - Forum Excel
A toutes fins utiles ==> https://www.commentcamarche.net/infos/25917-marquer-un-fil-de-discussion-comme-etant-resolu/
merci quand même.
cordialement.