October 18, 2010 at 11:31 am
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.
October 19, 2010 at 5:06 am
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.
October 19, 2010 at 6:37 am
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
October 19, 2010 at 11:45 am
Yeah the rownumber worked great! I am going to be using this for multiple uses now.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy