Advertisement
MaximErofeev

Untitled

Apr 16th, 2020
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 2.78 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 TOP 100
  6.     MasterListID, -- if you need this field for debugging, you can ask it.
  7.                 -- you don't need it to show to the user,
  8.                 -- hence you don't need it to ask in production.
  9.                 -- this field supposed to be unique for a particular storeId.
  10.                 -- so the combination of (MasterListID, StoreId) is unique.
  11.     DisplayName,
  12.     ItemNumber,
  13.     Description,
  14.     OrderQty
  15. FROM OrderListView olv
  16. WHERE olv.StoreId = ${action.storeId}
  17.     AND MasterListID > 0
  18. ORDER BY MasterListID
  19.  
  20. --(initially MasterListID > 0, after next scrolling MasterListID > 100 …)
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. --for the CombinedOrderList screen should be used another query.
  30. --The unfiltered (and limited) one:
  31.  
  32. SELECT TOP 100
  33.     v.DisplayName , ml.ItemNumber , ml.Description, jo.lastWeekQuantity, jo.thisWeekQuantity, ml.ItemInventoryCount,
  34.     ml.Id AS MLID, jo.OrderId
  35. FROM MasterList ml INNER JOIN Vendor v ON ml.VendorId = v.Id
  36.                         LEFT JOIN JoinedOrders jo ON
  37.                             ml.VendorId = jo.VendorId AND
  38.                             ml.ItemNumber = jo.ItemNumber AND
  39.                             ml.Description = jo.Description AND
  40.                             jo.StoreId = ${action.storeId}
  41. WHERE ml.Id > 0
  42. ORDER BY ml.Id
  43. --(initially ML.Id > 0, after next scrolling ML.Id > 100 …)
  44.  
  45.  
  46.  
  47. -- CombinedOrderList screen with example of applied filters:
  48.  
  49. SELECT TOP 100
  50.     v.DisplayName , ml.ItemNumber , ml.Description, jo.lastWeekQuantity, jo.thisWeekQuantity, ml.ItemInventoryCount,
  51.     ml.Id AS MLID, jo.OrderId
  52. FROM MasterList ml INNER JOIN Vendor v ON ml.VendorId = v.Id
  53.                         LEFT JOIN JoinedOrders jo ON
  54.                             ml.VendorId = jo.VendorId AND
  55.                             ml.ItemNumber = jo.ItemNumber AND
  56.                             ml.Description = jo.Description AND
  57.                             jo.StoreId = ${action.storeId}
  58. WHERE ml.Id > 0
  59.     AND V.DisplayName LIKE '%PD%'
  60.     AND ML.ItemNumber LIKE '%1024%'
  61.     AND ML.Description LIKE '%Glory%'
  62.  
  63. ORDER BY ml.Id
  64. --(initially ML.Id > 0, after next scrolling ML.Id > 100 …)
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. -- batch update            ${action.storeId}     ${action.userId}  
  72. INSERT INTO OrderListUpdate
  73.  ( OrderQty, MLID, OrderID,    StoreId,          ModifiedBy) VALUES
  74.  (    20,      3,     NULL,       8,                      8)      
  75. ,(    10,      4,       44,       8,                      8)      
  76. ,(     0,      5,       45,       8,                      8)
  77. ;
  78. -- to insert the order for MasterListID = 3 for 20
  79. -- to update the order with OrderId = 44 for 10
  80. -- to delete the order with OrderId = 45
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement