Advertisement
MaximErofeev

Untitled

Apr 29th, 2020
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 2.79 KB | None | 0 0
  1. --For the initial screen, that shows orders, that were placed during the current week,
  2. --you can use this query. It shows orders, sorted by the time of creation, freshest first.
  3. -- It could be used for the default order.
  4.  
  5. SELECT TOP 100
  6.     OrderId,
  7.     MasterListID,
  8.     VendorId,
  9.     DisplayName,
  10.     ItemNumber,
  11.     Description,
  12.     OrderQty,
  13.     CasePack,
  14.     Price
  15. FROM OrderListView olv
  16. WHERE olv.StoreId = 8
  17.      
  18. ORDER BY OrderId DESC
  19.  
  20. --for the first time, and
  21.  
  22. ............ -- (the SELECT clause stays same)
  23. WHERE olv.StoreId = 8
  24.      AND OrderId <100500  -- (smallest value of the OrderId field, that appeared in previous fetch. It was in the bottom of the resultset.)
  25. ORDER BY OrderId DESC
  26.  
  27. -- For the next fetch.
  28. -- Here we ask data by the OrderId and in top of the result would be the rows,
  29. -- with the biggest value of the OrderId ( "freshest" orders ).
  30. -- To fetch next 100 rows one need to remember the smallest previous value of the OrderId.
  31. -- and to insert it as a parameter
  32.  
  33.  
  34.  
  35.  
  36. -- To order it by Vendor asc:
  37.  
  38. WHERE olv.StoreId = 8
  39. ORDER BY DisplayName, ItemNumber
  40.  
  41. -- for the first set and:
  42.  
  43. WHERE olv.StoreId = 8 AND
  44.     olv.DisplayName >= "biggestPreviousValue" AND
  45.     olv.ItemNumber > "previousItemNumberShownForGivenVendor"
  46. ORDER BY DisplayName, ItemNumber
  47.  
  48. -- for the next fetch.
  49.  
  50.  
  51.  
  52.  
  53. -- To order by Vendor desc:  
  54.  
  55. WHERE olv.StoreId = 8
  56. ORDER BY DisplayName DESC, ItemNumber DESC
  57.  
  58. -- for the first set and:
  59.  
  60. WHERE olv.StoreId = 8 AND
  61.     olv.DisplayName <= "smallestPreviousValue" AND
  62.     olv.ItemNumber < "smallestItemNumberShownForGivenVendor"
  63. ORDER BY DisplayName DESC, ItemNumber DESC
  64.  
  65. -- for the next fetch.
  66.  
  67.  
  68.  
  69.  
  70. -- To order it by ItemNumber asc:
  71.  
  72. WHERE olv.StoreId = 8
  73. ORDER BY ItemNumber
  74.  
  75. -- for the first set and:
  76.  
  77. WHERE olv.StoreId = 8 AND
  78.     olv.ItemNumber > "previousBiggestItemNumberShown"
  79. ORDER BY ItemNumber
  80.  
  81. -- for the next fetch.
  82.  
  83.  
  84.  
  85.  
  86. -- To order it by ItemNumber desc:
  87.  
  88. WHERE olv.StoreId = 8
  89. ORDER BY ItemNumber DESC
  90.  
  91. -- for the first set and:
  92.  
  93. WHERE olv.StoreId = 8 AND
  94.     olv.ItemNumber < "previousSmallestItemNumberShown"
  95. ORDER BY ItemNumber DESC
  96.  
  97. -- for the next fetch.
  98.  
  99.  
  100.  
  101.  
  102. -- To order it by Description asc:
  103.  
  104. WHERE olv.StoreId = 8
  105. ORDER BY Description
  106.  
  107. -- for the first set and:
  108.  
  109. WHERE olv.StoreId = 8 AND
  110.     olv.Description > "previousBiggestDescriptionShown"
  111. ORDER BY Description
  112.  
  113. -- for the next fetch.
  114.  
  115.  
  116.  
  117.  
  118. -- To order it by Description desc:
  119.  
  120. WHERE olv.StoreId = 8
  121. ORDER BY Description DESC
  122.  
  123. -- for the first set and:
  124.  
  125. WHERE olv.StoreId = 8 AND
  126.     olv.Description < "previousSmallestDescriptionShown"
  127. ORDER BY Description DESC
  128.  
  129. -- for the next fetch.
  130.  
  131.  
  132.  
  133.  
  134.  
  135.     -- To order it by OrderQty… I think you got the idea.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement