In Bearbeitung Artikelverwaltung -> Retourenübersicht nach Plattform und Zeit

Thomas Lisson

Administrator
Mitarbeiter
24. März 2006
15.574
300
Köln
Hi zusammen,

anbei eine Übersicht über Retouren zum ausgewählten Artikel in der Artikelverwaltung. So könnt ihr schnell sehen, über welche Plattform die meisten Retouren kommen oder ab wann sie sich häufen, etc.
Berücksichtigt werden alle Retouren - egal in welchem Status sie sind. Für die Retourenquote werden alle Verkäufe gezählt - unabhängig davon, ob die Bestellungen ausgeliefert wurden.

SQL:
SELECT    tPlattform.cName AS 'Plattform',
        ISNULL(jAktMonat.rm, 0) AS 'Akt. Monat',
        ISNULL(jVorMonat.rm, 0) AS 'Vormonat',
        ISNULL(jLetzte30Tage.rm, 0) AS 'Letzte 30 Tage',
        ISNULL(jLetzte3Monate.rm, 0) AS 'Letzte 3 Monate',    
        ISNULL(jAktJahr.rm, 0) AS 'Akt. Jahr',
        ISNULL(jLetzte365Tage.rm, 0) AS 'Letzte 365 Tage',
        ISNULL(jVorjahr.rm, 0) AS 'Vorjahr',
        ISNULL(jGesamt.rm, 0) AS 'Gesamt',
        ISNULL(jRetourenGesamt.Retourenquote, '0%') AS 'Retourenquote'
FROM tPlattform
LEFT JOIN (
    SELECT    nPlatform,
            ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
            AND YEAR(tRMRetoure.dErstellt) = YEAR(getdate())
            AND MONTH(tRMRetoure.dErstellt) = MONTH(getdate())
    GROUP BY nPlatform
) as jAktMonat on jAktMonat.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT    nPlatform,
            ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
            AND YEAR(tRMRetoure.dErstellt) = YEAR(DATEADD(MONTH, -1, getdate()))
            AND MONTH(tRMRetoure.dErstellt) = MONTH(DATEADD(MONTH, -1, getdate()))
    GROUP BY nPlatform
) as jVorMonat on jVorMonat.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT    nPlatform,
            ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
            AND tRMRetoure.dErstellt > DATEADD(DAY, -30, getdate())
    GROUP BY nPlatform
) as jLetzte30Tage on jLetzte30Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT    nPlatform,
            ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
            AND tRMRetoure.dErstellt > DATEADD(MONTH, -3, getdate())
    GROUP BY nPlatform
) as jLetzte3Monate on jLetzte3Monate.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT    nPlatform,
            ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
            AND YEAR(tRMRetoure.dErstellt) = YEAR(getdate())
    GROUP BY nPlatform
) as jAktJahr on jAktJahr.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT    nPlatform,
            ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
            AND tRMRetoure.dErstellt > DATEADD(DAY, -365, getdate())
    GROUP BY nPlatform
) as jLetzte365Tage on jLetzte365Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT    nPlatform,
            ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
            AND YEAR(tRMRetoure.dErstellt) = YEAR(DATEADD(YEAR, -1, getdate()))
    GROUP BY nPlatform
) as jVorjahr on jVorjahr.nPlatform = tPlattform.nPlattform
JOIN (
    SELECT    nPlatform,
            ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
    GROUP BY nPlatform
) as jGesamt on jGesamt.nPlatform = tPlattform.nPlattform
LEFT JOIN (
SELECT jabsatzgesamt.nPlatform,
        CONCAT(ROUND((ISNULL(retourengesamt.rm, 0.0)/jabsatzgesamt.absatz)*100, 2), '%') as Retourenquote
FROM
(SELECT tbestellung.nPlatform,
    ROUND(CONVERT(FLOAT, ISNULL(SUM(tbestellpos.nAnzahl), 0.0)), 2) AS absatz
    FROM tbestellung
    JOIN tbestellpos ON tbestellpos.tBestellung_kBestellung = tBestellung.kBestellung
    WHERE tbestellpos.tArtikel_kArtikel = @Key
        AND tbestellung.cType = 'B'
        AND tBestellung.nStorno = 0 -- Stornierte Aufträge nicht beachten
    GROUP BY nPlatform) AS jabsatzgesamt
LEFT JOIN
    (SELECT nPlatform,
        ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
    GROUP BY nPlatform) AS retourengesamt on retourengesamt.nPlatform=jabsatzgesamt.nPlatform)
        as jRetourenGesamt on jRetourenGesamt.nPlatform = tPlattform.nPlattform
UNION
SELECT 'Alle Plattformen' AS 'Plattform',
    (SELECT ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
            AND YEAR(tRMRetoure.dErstellt) = YEAR(getdate())
            AND MONTH(tRMRetoure.dErstellt) = MONTH(getdate())) as 'Akt. Monat',
    (SELECT ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
            AND YEAR(tRMRetoure.dErstellt) = YEAR(DATEADD(MONTH, -1, getdate()))
            AND MONTH(tRMRetoure.dErstellt) = MONTH(DATEADD(MONTH, -1, getdate()))) as 'Vormonat',
    (SELECT ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
    AND tRMRetoure.dErstellt > DATEADD(DAY, -30, getdate())) as 'Letzte 30 Tage',
    (SELECT ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
    AND tRMRetoure.dErstellt > DATEADD(MONTH, -3, getdate())) as 'Letzte 3 Monate',
    (SELECT ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
    AND YEAR(tRMRetoure.dErstellt) = YEAR(getdate())) as 'Akt. Jahr',
    (SELECT ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
    AND tRMRetoure.dErstellt > DATEADD(DAY, -365, getdate())) as 'Letzte 365 Tage',
    (SELECT ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key
    AND YEAR(tRMRetoure.dErstellt) = YEAR(DATEADD(YEAR, -1, getdate()))) as 'Vorjahr',
    (SELECT ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key) as 'Gesamt',
    (SELECT CONCAT(ROUND((retourengesamt.rm/jabsatzgesamt.absatz)*100, 2), '%') as Retourenquote
FROM
(SELECT ROUND(CONVERT(FLOAT, ISNULL(SUM(tRMRetourePos.fAnzahl), 0.0)), 2) AS rm
    FROM tbestellung
    JOIN tRMRetoure ON tRMRetoure.kBestellung = tBestellung.kBestellung
    JOIN tRMRetourePos ON tRMRetourePos.kRMRetoure = tRMRetoure.kRMRetoure
    WHERE    tRMRetourePos.kArtikel = @Key) AS retourengesamt
JOIN
    (SELECT ROUND(CONVERT(FLOAT, ISNULL(SUM(tbestellpos.nAnzahl), 0.0)), 2) AS absatz
    FROM tbestellung
    JOIN tbestellpos ON tbestellpos.tBestellung_kBestellung = tBestellung.kBestellung
    WHERE tbestellpos.tArtikel_kArtikel = @Key
        AND tbestellung.cType = 'B') AS jabsatzgesamt on 1=1) AS Retourenquote
ORDER BY Plattform

EDIT am 27.09.2019 um 21:50

Viel Spaß damit!
 

Anhänge

  • LVE_Retouren.png
    LVE_Retouren.png
    12,6 KB · Aufrufe: 91
Zuletzt bearbeitet:

ROGUE

Sehr aktives Mitglied
11. September 2013
432
55
Hallo Zusammen,

der Script wäre auf jeden Fall mega geil. Nur leider funktioniert es nicht bei der Wawi 1.6. Könnte vielleicht jemand den Script für die Wawi 1.6 anpassen und hier posten?
Das wäre super hilfreich.

Vielen Dank im Voraus.
 
  • Gefällt mir
Reaktionen: Weedmaster-Flash

Ähnliche Themen