|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, February 08, 2013 1:52 PM
Points: 3,
Visits: 91
|
|
I have a request to return 100 rows of data per batch based on a variable passed to the my query. How do I do this?
Do I load my results to a temp table with an added id and make them use the id as their clause to pick the batch of data they need? This seems unneeded as I am sure there must be a better way to pass them the correct data. Any help would be appreciated.
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Sunday, August 26, 2012 6:05 PM
Points: 82,
Visits: 70
|
|
| if the requirement was known, then your underlying table must have been designed in the way you say.[a numeric / identity column]. if not, the easiest way to go about is what you have mentioned.
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 5:28 PM
Points: 11,627,
Visits: 27,692
|
|
here's one way to do it, using row number to select the batches of numbers;
declare @NumRows int declare @i int
SET @NumRows = 10 --return 10 rows at a time SET @i = 3 --i want the 3rd resultset, 30-40 SELECT * FROM ( SELECT row_number() OVER(ORDER BY name) AS RW, sysobjects.* FROM sysobjects ) myAlias WHERE myAlias.RW BETWEEN (@NumRows * @i) AND ((@NumRows * @i)+ @NumRows)
Lowell
--There is no spoon, and there's no default ORDER BY in sql server either. Actually, Common Sense is so rare, it should be considered a Superpower. --my son
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, February 08, 2013 1:52 PM
Points: 3,
Visits: 91
|
|
| Yeah the rownumber worked great! I am going to be using this for multiple uses now.
|
|
|
|