April 27, 2004 at 3:14 am
I have an SQL joining more than 5 tables. The results set contains over 10,000 records.
First time the SQL has to fetch only the first 25, then 2ed time with some parameters I should be able to fetch the next 25 and so on
How this can be done?
Now every time I execute the SQL it is fetching all the records.
April 27, 2004 at 5:53 am
http://www.microsoft.com/sql/techinfo/tips/administration/resultset.asp
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
April 28, 2004 at 3:03 am
Another way to do this with just sending in two parameters ( pagenbr, pagesize ).
Would be. ( example from Pubs )
SET NOCOUNT ON
DECLARE @pagenbr INT,
@pagesize INT,
@rows_skipped INT
SET @pagenbr = 2
SET @pagesize = 10
SET @rows_skipped = ( ( @pagenbr - 1 ) * @pagesize )
-- Declare table variable with PK of the table to page
DECLARE @table TABLE( au_id VARCHAR(11) )
IF @rows_skipped > 0
BEGIN
-- Insert skipped keys into table variable
-- important to order by key
SET ROWCOUNT @rows_skipped
INSERT @table SELECT au_id FROM authors ORDER BY au_id
END
SET ROWCOUNT @pagesize
SELECT
a.au_id,
a.au_fname + ' ' + au_lname AS name
FROM
authors a
WHERE
NOT EXISTS( SELECT t.au_id FROM @table t
WHERE t.au_id = a.au_id )
ORDER BY
a.au_id
/rockmoose
You must unlearn what You have learnt
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply