Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --For the initial screen, that shows orders, that were placed during the current week,
- --you can use this query. It shows orders, sorted by the time of creation, freshest first.
- -- It could be used for the default order.
- SELECT TOP 100
- OrderId,
- MasterListID,
- VendorId,
- DisplayName,
- ItemNumber,
- Description,
- OrderQty,
- CasePack,
- Price
- FROM OrderListView olv
- WHERE olv.StoreId = 8
- ORDER BY OrderId DESC
- --for the first time, and
- ............ -- (the SELECT clause stays same)
- WHERE olv.StoreId = 8
- AND OrderId <100500 -- (smallest value of the OrderId field, that appeared in previous fetch. It was in the bottom of the resultset.)
- ORDER BY OrderId DESC
- -- For the next fetch.
- -- Here we ask data by the OrderId and in top of the result would be the rows,
- -- with the biggest value of the OrderId ( "freshest" orders ).
- -- To fetch next 100 rows one need to remember the smallest previous value of the OrderId.
- -- and to insert it as a parameter
- -- To order it by Vendor asc:
- WHERE olv.StoreId = 8
- ORDER BY DisplayName, ItemNumber
- -- for the first set and:
- WHERE olv.StoreId = 8 AND
- olv.DisplayName >= "biggestPreviousValue" AND
- olv.ItemNumber > "previousItemNumberShownForGivenVendor"
- ORDER BY DisplayName, ItemNumber
- -- for the next fetch.
- -- To order by Vendor desc:
- WHERE olv.StoreId = 8
- ORDER BY DisplayName DESC, ItemNumber DESC
- -- for the first set and:
- WHERE olv.StoreId = 8 AND
- olv.DisplayName <= "smallestPreviousValue" AND
- olv.ItemNumber < "smallestItemNumberShownForGivenVendor"
- ORDER BY DisplayName DESC, ItemNumber DESC
- -- for the next fetch.
- -- To order it by ItemNumber asc:
- WHERE olv.StoreId = 8
- ORDER BY ItemNumber
- -- for the first set and:
- WHERE olv.StoreId = 8 AND
- olv.ItemNumber > "previousBiggestItemNumberShown"
- ORDER BY ItemNumber
- -- for the next fetch.
- -- To order it by ItemNumber desc:
- WHERE olv.StoreId = 8
- ORDER BY ItemNumber DESC
- -- for the first set and:
- WHERE olv.StoreId = 8 AND
- olv.ItemNumber < "previousSmallestItemNumberShown"
- ORDER BY ItemNumber DESC
- -- for the next fetch.
- -- To order it by Description asc:
- WHERE olv.StoreId = 8
- ORDER BY Description
- -- for the first set and:
- WHERE olv.StoreId = 8 AND
- olv.Description > "previousBiggestDescriptionShown"
- ORDER BY Description
- -- for the next fetch.
- -- To order it by Description desc:
- WHERE olv.StoreId = 8
- ORDER BY Description DESC
- -- for the first set and:
- WHERE olv.StoreId = 8 AND
- olv.Description < "previousSmallestDescriptionShown"
- ORDER BY Description DESC
- -- for the next fetch.
- -- To order it by OrderQty… I think you got the idea.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement