Neu Sichtbarkeit welcher Shop aktiv

Ryja

Gut bekanntes Mitglied
12. März 2019
164
10
Oberhütte
Firma
Projekte Agentur
Hi, gibt es die Möglichkeit einer Abfrage, für welchen Shop der Artikel aktiv/inaktiv ist?

Danke BG
 

John

Sehr aktives Mitglied
3. März 2012
4.269
1.111
Berlin
Ja, gibt es. Nimm das..

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
 
  • Gefällt mir
Reaktionen: Ryja

Ähnliche Themen