Hi all.
Forgive me for beating a dead horse but after reading many archived posts on this subject I still need some help. I have a stored procedure that returns a huge recordset to the end user. I would like to split this and take the Top 50, Next 50, Next 50 and so on. I've reviewed several possibilities including:
1. Using a temp table with an identity field - dumping all of the records into a temp table would take forever.
2. Select Top 50 ID From Table Where ID not in (Select Top 0 (50, 100, 150 etc) ID From Table) - I don't know what the subqueried 'Top' value will be until the sp is run and I cannot pass a parameter to it.
3. Using a subquery like this -
SELECT emp_id, lname, fname, job_id,
(SELECT COUNT(*) FROM employee e2 WHERE e2.emp_id <= e.emp_id AND e2.job_id = 10) AS rownumber
FROM employee e
WHERE job_id = 10
ORDER BY emp_id
In this case my original query involves far too many tables and joins to use this subquery.
Does anyone have any ideas? Am I missing something obvious?
Thanks for your help.
Forgive me for beating a dead horse but after reading many archived posts on this subject I still need some help. I have a stored procedure that returns a huge recordset to the end user. I would like to split this and take the Top 50, Next 50, Next 50 and so on. I've reviewed several possibilities including:
1. Using a temp table with an identity field - dumping all of the records into a temp table would take forever.
2. Select Top 50 ID From Table Where ID not in (Select Top 0 (50, 100, 150 etc) ID From Table) - I don't know what the subqueried 'Top' value will be until the sp is run and I cannot pass a parameter to it.
3. Using a subquery like this -
SELECT emp_id, lname, fname, job_id,
(SELECT COUNT(*) FROM employee e2 WHERE e2.emp_id <= e.emp_id AND e2.job_id = 10) AS rownumber
FROM employee e
WHERE job_id = 10
ORDER BY emp_id
In this case my original query involves far too many tables and joins to use this subquery.
Does anyone have any ideas? Am I missing something obvious?
Thanks for your help.