Neu Artikelverwaltung -> Aktivität pro Plattform nach FBA und FBM

chx_de

Gut bekanntes Mitglied
12. August 2016
118
13
Hi zusammen,

wir nutzen die Übersicht zu den Beständen und Verkäufen je Plattform. Besteht irgendwie die Möglichkeit, dass im Bereich Amazon die Absatzzahlen noch nach FBA und FBM aufgesplittet werden? Menge und Preis sind ja schon aufgesplittet. Angemerkt sei hierzu, dass wir unsere Artikel als FBA Artikel bei Amazon einstellen und noch mal als Mehrfachlisting mit Versand durch uns (FBM).

Für FBA und FBM SKU werden dann aber immer die Absätze summiert.
z.B.: Zeile 3 ist das FBA Angebot in DE und Zeile 4 wäre das FBM Mehrfachlisting in DE

capture20200425152653866.png

Code:
-Amazon Angebote
SELECT tPlattform.cName AS 'Plattform',
        jAmazon.nQuantity AS 'Menge',
        jAmazon.fPrice AS 'Akt. Preis',
        ISNULL(jLetzte30Tage.absatz, 0) AS 'Absatz 30 Tage',
        ISNULL(jLetzte90Tage.absatz, 0) AS 'Abs. 90 Tage',
        ISNULL(jLetzte365Tage.absatz, 0) AS 'Abs. 365 Tage',
        ISNULL(jAbsatzGesamt.absatz, 0) AS 'Abs. Gesamt',
        ISNULL(jVKDurchschnitt.vk, 0) 'Ø VK-Brutto',
        ISNULL(jAmazon.cASIN1, '') AS 'ID'
FROM tPlattform
JOIN ( --läuft er überhaupt auf amazon?
    SELECT    nPlattform,
            nQuantity,
            ROUND(CONVERT(FLOAT, fPrice), 2) AS fPrice,
            pf_amazon_angebot.cASIN1
    FROM pf_amazon_angebot
    JOIN pf_amazon_angebot_mapping ON pf_amazon_angebot_mapping.cSellerSKU = pf_amazon_angebot.cSellerSKU
        AND pf_amazon_angebot_mapping.kUser = pf_amazon_angebot.kUser
    WHERE pf_amazon_angebot_mapping.kArtikel = @Key
    ) AS jAmazon ON jAmazon.nPlattform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -30, getdate())
    GROUP BY nPlatform
) AS jLetzte30Tage ON jLetzte30Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -90, getdate())
    GROUP BY nPlatform
) AS jLetzte90Tage ON jLetzte90Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -365, getdate())
    GROUP BY nPlatform
) AS jLetzte365Tage ON jLetzte365Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY nPlatform
) AS jAbsatzGesamt ON jAbsatzGesamt.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT nPlatform, ROUND(CONVERT(FLOAT, ISNULL(AVG(tbestellpos.fVKPreis), 0.0)), 2) AS vk
    FROM tbestellpos
    JOIN tBestellung ON tbestellpos.tBestellung_kBestellung = tBestellung.kBestellung
    WHERE tbestellpos.tArtikel_kArtikel = @Key
        AND tBestellung.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY nPlatform
) AS jVKDurchschnitt ON jVKDurchschnitt.nPlatform = tPlattform.nPlattform
UNION --eBay Angebote - normale Artikel
SELECT tPlattform.cName AS 'Plattform',
        ISNULL(jEbay.Quantity, 0) AS 'Menge',
        ISNULL(jEbay.StartPrice, 0) AS 'Akt. Preis',
        ISNULL(jLetzte30Tage.absatz, 0) AS 'Absatz 30 Tage',
        ISNULL(jLetzte90Tage.absatz, 0) AS 'Abs. 90 Tage',
        ISNULL(jLetzte365Tage.absatz, 0) AS 'Abs. 365 Tage',
        ISNULL(jAbsatzGesamt.absatz, 0) AS 'Abs. Gesamt',
        ISNULL(jVKDurchschnitt.vk, 0) 'Ø VK-Brutto',
        ISNULL(jEbay.ItemID, '') AS 'ID'
FROM tPlattform
JOIN ( --läuft er überhaupt auf ebay?
 SELECT    ebay_xx_sites.kPlattform,
        ebay_item.Quantity,
        ROUND(CONVERT(FLOAT, ebay_item.StartPrice), 2) AS StartPrice,
        ebay_item.ItemID
    FROM ebay_item
    JOIN ebay_xx_sites ON ebay_xx_sites.SiteID = ebay_item.SiteID
    WHERE    ebay_item.kArtikel = @Key
        AND ebay_item.Status IN (3,7)
) AS jEbay ON jEbay.kPlattform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -30, getdate())
    GROUP BY nPlatform
) AS jLetzte30Tage ON jLetzte30Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -90, getdate())
    GROUP BY nPlatform
) AS jLetzte90Tage ON jLetzte90Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -365, getdate())
    GROUP BY nPlatform
) AS jLetzte365Tage ON jLetzte365Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY nPlatform
) AS jAbsatzGesamt ON jAbsatzGesamt.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT nPlatform, ROUND(CONVERT(FLOAT, ISNULL(AVG(tbestellpos.fVKPreis), 0.0)), 2) AS vk
    FROM tbestellpos
    JOIN tBestellung ON tbestellpos.tBestellung_kBestellung = tBestellung.kBestellung
    WHERE tbestellpos.tArtikel_kArtikel = @Key
        AND tBestellung.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY nPlatform
) AS jVKDurchschnitt ON jVKDurchschnitt.nPlatform = tPlattform.nPlattform
UNION --eBay Angebote - als Kindartikel im eBay Variationsangebot
SELECT tPlattform.cName AS 'Plattform',
        jEbay.fAnzahl AS 'Menge',
        jEbay.fPreis AS 'Akt. Preis',
        ISNULL(jLetzte30Tage.absatz, 0) AS 'Absatz 30 Tage',
        ISNULL(jLetzte90Tage.absatz, 0) AS 'Abs. 90 Tage',
        ISNULL(jLetzte365Tage.absatz, 0) AS 'Abs. 365 Tage',
        ISNULL(jAbsatzGesamt.absatz, 0) AS 'Abs. Gesamt',
        ISNULL(jVKDurchschnitt.vk, 0) 'Ø VK-Brutto',
        CONCAT('Varkombi-Kind: ', jEbay.ItemID) AS 'ID'
FROM tPlattform
JOIN ( --läuft er überhaupt auf ebay als Kindartikel?
 SELECT    ebay_xx_sites.kPlattform,
        CONVERT(INT, ebay_item2kombi.fAnzahl) AS fAnzahl,
        ROUND(CONVERT(FLOAT, ebay_item2kombi.fPreis), 2) AS fPreis,
        ebay_item.ItemID
    FROM ebay_item
    JOIN ebay_xx_sites ON ebay_xx_sites.SiteID = ebay_item.SiteID
    JOIN ebay_item2kombi ON ebay_item2kombi.kItem = ebay_item.kItem
    JOIN tartikel ON tartikel.kEigenschaftKombi = ebay_item2kombi.kEigenschaftKombi
    WHERE    tartikel.kArtikel = @Key
        AND ebay_item.Status IN (3,7)
) AS jEbay ON jEbay.kPlattform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -30, getdate())
    GROUP BY nPlatform
) AS jLetzte30Tage ON jLetzte30Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -90, getdate())
    GROUP BY nPlatform
) AS jLetzte90Tage ON jLetzte90Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -365, getdate())
    GROUP BY nPlatform
) AS jLetzte365Tage ON jLetzte365Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY nPlatform
) AS jAbsatzGesamt ON jAbsatzGesamt.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT nPlatform, ROUND(CONVERT(FLOAT, ISNULL(AVG(tbestellpos.fVKPreis), 0.0)), 2) AS vk
    FROM tbestellpos
    JOIN tBestellung ON tbestellpos.tBestellung_kBestellung = tBestellung.kBestellung
    WHERE tbestellpos.tArtikel_kArtikel = @Key
        AND tBestellung.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY nPlatform
) AS jVKDurchschnitt ON jVKDurchschnitt.nPlatform = tPlattform.nPlattform
UNION --eBay Angebote - als Kindartikel im eBay Variationsangebot
SELECT tShop.cName AS 'Plattform',
        ISNULL(jShop.fVerfuegbar, 0) AS 'Menge',
        ROUND(CONVERT(FLOAT, dbo.ifGetPrice(jShop.kArtikel, 0, 1, jShop.kShop, 1) * (100 + jShop.fSteuersatz) / 100), 2) AS 'Akt. Preis',
        ISNULL(jLetzte30Tage.absatz, 0) AS 'Absatz 30 Tage',
        ISNULL(jLetzte90Tage.absatz, 0) AS 'Abs. 90 Tage',
        ISNULL(jLetzte365Tage.absatz, 0) AS 'Abs. 365 Tage',
        ISNULL(jAbsatzGesamt.absatz, 0) AS 'Abs. Gesamt',
        ISNULL(jVKDurchschnitt.vk, 0) 'Ø VK-Brutto',
        jShop.cArtNr AS 'ID'
FROM tShop
JOIN ( --läuft er in Shops oder POS, etc.?
 SELECT    tArtikelShop.kShop,
        tArtikelShop.kArtikel,
        ROUND(CONVERT(FLOAT, ISNULL(vLagerbestandEx.fVerfuegbar, 0)), 2) AS fVerfuegbar,
        tartikel.cArtNr,
        tSteuersatz.fSteuersatz AS fSteuersatz
    FROM tartikel
    JOIN tArtikelShop ON tArtikelShop.kArtikel = tartikel.kArtikel
    LEFT JOIN vLagerbestandEx ON vLagerbestandEx.kArtikel = tartikel.kArtikel
JOIN (
SELECT TOP 1 kFirma, cLandISO FROM tFirma
ORDER by kFirma) AS jFirma ON 1=1
JOIN tSteuerzoneLand ON tSteuerzoneLand.cISO = jFirma.cLandISO
JOIN tSteuerzone ON tSteuerzone.kSteuerzone = tSteuerzoneLand.kSteuerzone
    AND tSteuerzone.kFirma = 0
JOIN tSteuersatz ON tSteuersatz.kSteuerzone = tSteuerzone.kSteuerzone
    AND tSteuersatz.kSteuerklasse = tartikel.kSteuerklasse
    WHERE    tartikel.kArtikel = @Key
        AND tArtikelShop.cDelInet != 'Y'
) AS jShop ON jShop.kShop = tShop.kShop
LEFT JOIN (
    SELECT kShop, 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -30, getdate())
    GROUP BY kShop
) AS jLetzte30Tage ON jLetzte30Tage.kShop = tShop.kShop
LEFT JOIN (
    SELECT kShop, 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -90, getdate())
    GROUP BY kShop
) AS jLetzte90Tage ON jLetzte90Tage.kShop = tShop.kShop
LEFT JOIN (
    SELECT kShop, 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -365, getdate())
    GROUP BY kShop
) AS jLetzte365Tage ON jLetzte365Tage.kShop = tShop.kShop
LEFT JOIN (
    SELECT kShop, 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY kShop
) AS jAbsatzGesamt ON jAbsatzGesamt.kShop = tShop.kShop
LEFT JOIN (
    SELECT kShop, ROUND(CONVERT(FLOAT, ISNULL(AVG(tbestellpos.fVKPreis), 0.0)), 2) AS vk
    FROM tbestellpos
    JOIN tBestellung ON tbestellpos.tBestellung_kBestellung = tBestellung.kBestellung
    WHERE tbestellpos.tArtikel_kArtikel = @Key
        AND tBestellung.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY kShop
) AS jVKDurchschnitt ON jVKDurchschnitt.kShop = tShop.kShop

Viele Grüße
Christian
 

Anhänge

  • capture20200425152521549.png
    capture20200425152521549.png
    32,2 KB · Aufrufe: 5
  • Gefällt mir
Reaktionen: Leff

chx_de

Gut bekanntes Mitglied
12. August 2016
118
13
UPDATE:
Ich habe eine Lösung gefunden. Allerdings habe ich für uns die Spalten Menge, Absatz Gesamt sowie durchschnittlicher VK und ID entfernt, da nicht benötigt.

Code:
--Amazon FBA Angebote
SELECT ( tPlattform.cName + ' FBA') AS 'Plattform',
        ISNULL(jLetzte30Tage.absatz, 0) AS 'Absatz 30 Tage',
        ISNULL(jLetzte90Tage.absatz, 0) AS 'Abs. 90 Tage',
        ISNULL(jLetzte365Tage.absatz, 0) AS 'Abs. 365 Tage'
FROM tPlattform
JOIN ( --läuft er überhaupt auf amazon?
    SELECT  nPlattform
    FROM pf_amazon_angebot
    JOIN pf_amazon_angebot_mapping ON pf_amazon_angebot_mapping.cSellerSKU = pf_amazon_angebot.cSellerSKU
        AND pf_amazon_angebot_mapping.kUser = pf_amazon_angebot.kUser
    WHERE pf_amazon_angebot_mapping.kArtikel = @Key
    ) AS jAmazon ON jAmazon.nPlattform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -30, getdate())
        AND tBestellung.cAnmerkung LIKE 'FBA%'
    GROUP BY nPlatform
) AS jLetzte30Tage ON jLetzte30Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -90, getdate())
        AND tBestellung.cAnmerkung LIKE 'FBA%'
    GROUP BY nPlatform
) AS jLetzte90Tage ON jLetzte90Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -365, getdate())
        AND tBestellung.cAnmerkung LIKE 'FBA%'
    GROUP BY nPlatform
) AS jLetzte365Tage ON jLetzte365Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.cAnmerkung LIKE 'FBA%'
    GROUP BY nPlatform
) AS jAbsatzGesamt ON jAbsatzGesamt.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT nPlatform, ROUND(CONVERT(FLOAT, ISNULL(AVG(tbestellpos.fVKPreis), 0.0)), 2) AS vk
    FROM tbestellpos
    JOIN tBestellung ON tbestellpos.tBestellung_kBestellung = tBestellung.kBestellung
    WHERE tbestellpos.tArtikel_kArtikel = @Key
        AND tBestellung.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.cAnmerkung LIKE 'FBA%'
    GROUP BY nPlatform
) AS jVKDurchschnitt ON jVKDurchschnitt.nPlatform = tPlattform.nPlattform


UNION -- AMZON FBM Angebote
SELECT tPlattform.cName AS 'Plattform',
        ISNULL(jLetzte30Tage.absatz, 0) AS 'Absatz 30 Tage',
        ISNULL(jLetzte90Tage.absatz, 0) AS 'Abs. 90 Tage',
        ISNULL(jLetzte365Tage.absatz, 0) AS 'Abs. 365 Tage'
FROM tPlattform
JOIN ( --läuft er überhaupt auf amazon?
    SELECT  nPlattform
    FROM pf_amazon_angebot
    JOIN pf_amazon_angebot_mapping ON pf_amazon_angebot_mapping.cSellerSKU = pf_amazon_angebot.cSellerSKU
        AND pf_amazon_angebot_mapping.kUser = pf_amazon_angebot.kUser
    WHERE pf_amazon_angebot_mapping.kArtikel = @Key
    ) AS jAmazon ON jAmazon.nPlattform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -30, getdate())
        AND tBestellung.cAnmerkung NOT LIKE 'FBA%'
    GROUP BY nPlatform
) AS jLetzte30Tage ON jLetzte30Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -90, getdate())
        AND tBestellung.cAnmerkung NOT LIKE 'FBA%'
    GROUP BY nPlatform
) AS jLetzte90Tage ON jLetzte90Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -365, getdate())
        AND tBestellung.cAnmerkung NOT LIKE 'FBA%'
    GROUP BY nPlatform
) AS jLetzte365Tage ON jLetzte365Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.cAnmerkung NOT LIKE 'FBA%'
    GROUP BY nPlatform
) AS jAbsatzGesamt ON jAbsatzGesamt.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT nPlatform, ROUND(CONVERT(FLOAT, ISNULL(AVG(tbestellpos.fVKPreis), 0.0)), 2) AS vk
    FROM tbestellpos
    JOIN tBestellung ON tbestellpos.tBestellung_kBestellung = tBestellung.kBestellung
    WHERE tbestellpos.tArtikel_kArtikel = @Key
        AND tBestellung.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.cAnmerkung NOT LIKE 'FBA%'
    GROUP BY nPlatform
) AS jVKDurchschnitt ON jVKDurchschnitt.nPlatform = tPlattform.nPlattform


UNION --eBay Angebote - normale Artikel
SELECT tPlattform.cName AS 'Plattform',
        ISNULL(jLetzte30Tage.absatz, 0) AS 'Absatz 30 Tage',
        ISNULL(jLetzte90Tage.absatz, 0) AS 'Abs. 90 Tage',
        ISNULL(jLetzte365Tage.absatz, 0) AS 'Abs. 365 Tage'
FROM tPlattform
JOIN ( --läuft er überhaupt auf ebay?
 SELECT ebay_xx_sites.kPlattform,
        ebay_item.ItemID
    FROM ebay_item
    JOIN ebay_xx_sites ON ebay_xx_sites.SiteID = ebay_item.SiteID
    WHERE    ebay_item.kArtikel = @Key
        AND ebay_item.Status IN (3,7)
) AS jEbay ON jEbay.kPlattform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -30, getdate())
    GROUP BY nPlatform
) AS jLetzte30Tage ON jLetzte30Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -90, getdate())
    GROUP BY nPlatform
) AS jLetzte90Tage ON jLetzte90Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -365, getdate())
    GROUP BY nPlatform
) AS jLetzte365Tage ON jLetzte365Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY nPlatform
) AS jAbsatzGesamt ON jAbsatzGesamt.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT nPlatform, ROUND(CONVERT(FLOAT, ISNULL(AVG(tbestellpos.fVKPreis), 0.0)), 2) AS vk
    FROM tbestellpos
    JOIN tBestellung ON tbestellpos.tBestellung_kBestellung = tBestellung.kBestellung
    WHERE tbestellpos.tArtikel_kArtikel = @Key
        AND tBestellung.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY nPlatform
) AS jVKDurchschnitt ON jVKDurchschnitt.nPlatform = tPlattform.nPlattform
UNION --eBay Angebote - als Kindartikel im eBay Variationsangebot
SELECT tPlattform.cName AS 'Plattform',
        ISNULL(jLetzte30Tage.absatz, 0) AS 'Absatz 30 Tage',
        ISNULL(jLetzte90Tage.absatz, 0) AS 'Abs. 90 Tage',
        ISNULL(jLetzte365Tage.absatz, 0) AS 'Abs. 365 Tage'
FROM tPlattform
JOIN ( --läuft er überhaupt auf ebay als Kindartikel?
 SELECT    ebay_xx_sites.kPlattform,
        ebay_item.ItemID
    FROM ebay_item
    JOIN ebay_xx_sites ON ebay_xx_sites.SiteID = ebay_item.SiteID
    JOIN ebay_item2kombi ON ebay_item2kombi.kItem = ebay_item.kItem
    JOIN tartikel ON tartikel.kEigenschaftKombi = ebay_item2kombi.kEigenschaftKombi
    WHERE    tartikel.kArtikel = @Key
        AND ebay_item.Status IN (3,7)
) AS jEbay ON jEbay.kPlattform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -30, getdate())
    GROUP BY nPlatform
) AS jLetzte30Tage ON jLetzte30Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -90, getdate())
    GROUP BY nPlatform
) AS jLetzte90Tage ON jLetzte90Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -365, getdate())
    GROUP BY nPlatform
) AS jLetzte365Tage ON jLetzte365Tage.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY nPlatform
) AS jAbsatzGesamt ON jAbsatzGesamt.nPlatform = tPlattform.nPlattform
LEFT JOIN (
    SELECT nPlatform, ROUND(CONVERT(FLOAT, ISNULL(AVG(tbestellpos.fVKPreis), 0.0)), 2) AS vk
    FROM tbestellpos
    JOIN tBestellung ON tbestellpos.tBestellung_kBestellung = tBestellung.kBestellung
    WHERE tbestellpos.tArtikel_kArtikel = @Key
        AND tBestellung.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY nPlatform
) AS jVKDurchschnitt ON jVKDurchschnitt.nPlatform = tPlattform.nPlattform
UNION --SHOP Angebote
SELECT tShop.cName AS 'Plattform',
        ISNULL(jLetzte30Tage.absatz, 0) AS 'Absatz 30 Tage',
        ISNULL(jLetzte90Tage.absatz, 0) AS 'Abs. 90 Tage',
        ISNULL(jLetzte365Tage.absatz, 0) AS 'Abs. 365 Tage'
FROM tShop
JOIN ( --läuft er in Shops oder POS, etc.?
 SELECT tArtikelShop.kShop,
        tArtikelShop.kArtikel,
        ROUND(CONVERT(FLOAT, ISNULL(vLagerbestandEx.fVerfuegbar, 0)), 2) AS fVerfuegbar,
        tartikel.cArtNr,
        tSteuersatz.fSteuersatz AS fSteuersatz
    FROM tartikel
    JOIN tArtikelShop ON tArtikelShop.kArtikel = tartikel.kArtikel
    LEFT JOIN vLagerbestandEx ON vLagerbestandEx.kArtikel = tartikel.kArtikel
JOIN (
SELECT TOP 1 kFirma, cLandISO FROM tFirma
ORDER by kFirma) AS jFirma ON 1=1
JOIN tSteuerzoneLand ON tSteuerzoneLand.cISO = jFirma.cLandISO
JOIN tSteuerzone ON tSteuerzone.kSteuerzone = tSteuerzoneLand.kSteuerzone
    AND tSteuerzone.kFirma = 0
JOIN tSteuersatz ON tSteuersatz.kSteuerzone = tSteuerzone.kSteuerzone
    AND tSteuersatz.kSteuerklasse = tartikel.kSteuerklasse
    WHERE    tartikel.kArtikel = @Key
        AND tArtikelShop.cDelInet != 'Y'
) AS jShop ON jShop.kShop = tShop.kShop
LEFT JOIN (
    SELECT kShop, 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -30, getdate())
    GROUP BY kShop
) AS jLetzte30Tage ON jLetzte30Tage.kShop = tShop.kShop
LEFT JOIN (
    SELECT kShop, 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -90, getdate())
    GROUP BY kShop
) AS jLetzte90Tage ON jLetzte90Tage.kShop = tShop.kShop
LEFT JOIN (
    SELECT kShop, 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
        AND tBestellung.dErstellt > DATEADD(DAY, -365, getdate())
    GROUP BY kShop
) AS jLetzte365Tage ON jLetzte365Tage.kShop = tShop.kShop
LEFT JOIN (
    SELECT kShop, 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.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY kShop
) AS jAbsatzGesamt ON jAbsatzGesamt.kShop = tShop.kShop
LEFT JOIN (
    SELECT kShop, ROUND(CONVERT(FLOAT, ISNULL(AVG(tbestellpos.fVKPreis), 0.0)), 2) AS vk
    FROM tbestellpos
    JOIN tBestellung ON tbestellpos.tBestellung_kBestellung = tBestellung.kBestellung
    WHERE tbestellpos.tArtikel_kArtikel = @Key
        AND tBestellung.nStorno = 0 -- Stornierte Aufträge nicht beachten
        AND tbestellung.cType = 'B'
    GROUP BY kShop
) AS jVKDurchschnitt ON jVKDurchschnitt.kShop = tShop.kShop
 

Anhänge

  • capture20200425173643811.png
    capture20200425173643811.png
    24,1 KB · Aufrufe: 15
Zuletzt bearbeitet: