Advertisement
Guest User

Untitled

a guest
May 28th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.02 KB | None | 0 0
  1. SELECT
  2.       si.MdtId
  3.     , m.MdtNumber
  4.     , m.MdtName
  5.     , s.StoreNumber
  6.     , s.StoreName
  7.     , YEAR(si.StartDate) AS Jahr
  8.     , MONTH(si.StartDate) AS Monat
  9.     , (SELECT COUNT(si2.IdStockItem) FROM tblStockItem si2 WHERE si2.MdtId = si.MdtId AND si2.StoreId = si.StoreId
  10.         AND YEAR(si2.StartDate) = YEAR(si.StartDate) AND MONTH(si.StartDate) = MONTH(si2.StartDate)) AS [ZurückUmschläge]
  11.     , (SELECT CASE WHEN SUM(Amount) IS NULL THEN 0 ELSE SUM(Amount) END FROM tblEnvelope e WHERE e.MdtID = si.MdtId AND e.StoreID = si.StoreId
  12.         AND YEAR(e.DeliveryDate) = YEAR(si.StartDate) AND MONTH(e.DeliveryDate) = MONTH(si.StartDate)) AS [geliefertumschläge]
  13. FROM tblStockItem si
  14.     JOIN tblMandant m ON si.MdtId = m.IdMdt
  15.     JOIN tblStores s ON s.IdStore = si.StoreId
  16. WHERE YEAR(si.StartDate)>= 2014 AND si.MdtId = 79 AND si.StoreId = 2610
  17. GROUP BY si.MdtId, m.MdtNumber, m.MdtName, s.StoreNumber, s.StoreName, YEAR(si.StartDate), MONTH(si.StartDate), si.StoreId
  18. ORDER BY YEAR(si.StartDate), MONTH(si.StartDate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement