Paging

  • Hello,

    I have a product table in my database I want to display all products (300000) in my windows application but 10 after 10 ,How can I do that in the select statement?

  • If you aren't using SqlServer Compact Edition you can use TOP to limit the results returned:

    SELECT TOP(10) * from ProductTable WHERE ProdID > xxxMaxLastProdID ORDER BY ProdID ASC

    This returns the next 10 results from your table. Execute this iteratively, changing xxxMaxLastProdID to the largest ProdID you received in the last set.

    If you are using SqlServer Compact Edition TOP is not available. You will have to grab a sorted list of all ProdID's from your ProductTable, then step thru that list 10 at a time to define the min and max ProdIDs in a WHERE clause:

    SELECT * from ProductTable WHERE ProdID >= xxxMinProdID AND ProdID <= xxxMaxProdID ORDER BY ProdID ASC

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply