SQL SUM(Case when)
Hallo Zusammen,
kann man den folgenden Code auch kürzer schreiben?...
ich dachte da an eine OR als Verknüpfung leider bekomme ich da andere Ergebnisse...
Grüße Florian
kann man den folgenden Code auch kürzer schreiben?...
sum(case when NSDM_V_MSEG.BWART = 101 then NSDM_V_MSEG.MENGE * 1
when NSDM_V_MSEG.BWART = 102 then NSDM_V_MSEG.MENGE * -1
when NSDM_V_MSEG.BWART = 262 then NSDM_V_MSEG.MENGE * 1
when NSDM_V_MSEG.BWART = 261 then NSDM_V_MSEG.MENGE * -1
ich dachte da an eine OR als Verknüpfung leider bekomme ich da andere Ergebnisse...
sum(case when NSDM_V_MSEG.BWART = 101 OR NSDM_V_MSEG.BWART = 262 then NSDM_V_MSEG.MENGE * 1
when NSDM_V_MSEG.BWART = 102 OR NSDM_V_MSEG.BWART = 261 then NSDM_V_MSEG.MENGE * -1
Grüße Florian
Please also mark the comments that contributed to the solution of the article
Content-Key: 648119
Url: https://administrator.de/contentid/648119
Printed on: April 19, 2024 at 07:04 o'clock
2 Comments
Latest comment
Moin
Gruß
em-pie
Zitat von @LauneBaer:
Geht noch kürzer:sum(case when (NSDM_V_MSEG.BWART = 101 OR NSDM_V_MSEG.BWART = 262) then NSDM_V_MSEG.MENGE * 1
> when (NSDM_V_MSEG.BWART = 102 OR NSDM_V_MSEG.BWART = 261) then NSDM_V_MSEG.MENGE * -1
sum(case
when NSDM_V_MSEG.BWART in (101, 262) then NSDM_V_MSEG.MENGE * 1
when NSDM_V_MSEG.BWART in (102, 261) then NSDM_V_MSEG.MENGE * -1
END)
Gruß
em-pie