Advertisement
MaximErofeev

Untitled

Apr 8th, 2020
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 3.07 KB | None | 0 0
  1. --For the initial screen, that shows orders, that were placed during the current week,
  2. --this query should be used:
  3.  
  4.  
  5. SELECT
  6.     Vendor.DisplayName AS VendorDisplayName,
  7.     MasterList.ItemNumber,
  8.     MasterList.Description,
  9.     OrderList.OrderQty,
  10.     MasterList.Id,
  11.     MasterList.VendorId
  12. FROM MasterList
  13.         JOIN Vendor ON (MasterList.VendorId = Vendor.Id)
  14.         JOIN OrderList ON (
  15.             MasterList.VendorId = OrderList.VendorId AND
  16.             MasterList.ItemNumber = OrderList.ItemNumber AND
  17.             MasterList.Description = OrderList.Description AND
  18.             OrderList.CreatedOn > dbo.weekStart() AND
  19.              OrderList.StoreId = ${action.storeId}
  20.         )
  21. WHERE OrderList.StoreId = ${action.storeId}
  22.  
  23.  
  24.  
  25. --for the CombinedOrderList screen should be used another query.
  26. --The unfiltered (and limited) one:
  27.  
  28.  
  29. SELECT top(100)
  30.     V.DisplayName AS VENDOR,
  31.     ML.ItemNumber AS ITEM,
  32.     ML.DESCRIPTION AS DESCRIPTION,
  33.     OLL.OrderQty AS LAST_WEEK,
  34.     OL.OrderQty AS THIS_WEEK,
  35.     ML.ItemInventoryCount AS INVENTORY,
  36.     OL.StoreId AS STORE_ID,
  37.     OL.Id AS ORDER_ID,
  38.     ML.Id AS MASTER_ID
  39. FROM dbo.MasterList ML JOIN dbo.Vendor V ON ML.VendorId = V.Id
  40.     LEFT JOIN dbo.OrderList OLL ON
  41.             ML.VendorId = OLL.VendorId
  42.         AND ML.ItemNumber = OLL.ItemNumber
  43.         AND ML.Description = OLL.Description
  44.         AND OLL.CreatedOn <=dbo2.weekStart()
  45.         AND OLL.CreatedOn > dateadd(week, -1, dbo2.weekStart())
  46.          AND OLL.StoreId = ${action.storeId}
  47.     LEFT JOIN dbo.OrderList OL ON
  48.             ML.VendorId = OL.VendorId
  49.         AND ML.ItemNumber = OL.ItemNumber
  50.         AND ML.Description = OL.Description
  51.         AND OL.CreatedOn > dbo2.weekStart()
  52.          AND OLL.StoreId = ${action.storeId}
  53. WHERE
  54.      ML.Id > 0
  55. ORDER BY ML.Id
  56. --(initially ML.Id > 0, after next scrolling ML.Id > 100 …)
  57.  
  58.  
  59.  
  60. -- CombinedOrderList screen with example of applied filters:
  61.  
  62.  
  63. SELECT top(100)
  64.         V.DisplayName AS VENDOR,
  65.         ML.ItemNumber AS ITEM,
  66.         ML.DESCRIPTION AS DESCRIPTION,
  67.         OLL.OrderQty AS LAST_WEEK,
  68.         OL.OrderQty AS THIS_WEEK,
  69.         ML.ItemInventoryCount AS INVENTORY,
  70.         OL.StoreId AS STORE_ID,
  71.         OL.Id AS ORDER_ID,
  72.         ML.Id AS MASTER_ID
  73. FROM dbo.MasterList ML JOIN dbo.Vendor V ON ML.VendorId = V.Id
  74.     LEFT JOIN dbo.OrderList OLL ON
  75.             ML.VendorId = OLL.VendorId
  76.         AND ML.ItemNumber = OLL.ItemNumber
  77.         AND ML.Description = OLL.Description
  78.         AND OLL.CreatedOn <=dbo2.weekStart()
  79.         AND OLL.CreatedOn > dateadd(week, -1, dbo2.weekStart())
  80.          AND OLL.StoreId = ${action.storeId}
  81.     LEFT JOIN dbo.OrderList OL ON
  82.             ML.VendorId = OL.VendorId
  83.         AND ML.ItemNumber = OL.ItemNumber
  84.         AND ML.Description = OL.Description
  85.         AND OL.CreatedOn > dbo2.weekStart()
  86.          AND OL.StoreId = ${action.storeId}
  87.  
  88. WHERE
  89.          V.DisplayName LIKE '%PD%'
  90.     AND ML.ItemNumber LIKE '%1024%'
  91.     AND ML.Description LIKE '%Glory%'
  92.  
  93.     AND ML.Id > 0
  94. ORDER BY ML.Id
  95. --(initially ML.Id > 0, after next scrolling ML.Id > 100 …)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement