Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with SQL count

Author  Topic 

dave1nc
Starting Member

2 Posts

Posted - 2011-07-06 : 16:21:56
The following MS-SQL query returns over 5,000 records. I would like for it to only return 500 rows at one time.

There is a column named employee_id and the numbers range from 000000059 to 001592258.

select * from stage_person_import_temp a
where a.status_dt = (select max(b.status_dt)
from stage_person_import_temp b
where b.employee_id = a.employee_id
)
and a.record_count =(select min(c.record_count)
from stage_person_import_temp c
where a.employee_id = c.employee_id
and a.status_dt = c.status_dt
)
order by a.employee_id

Thanks so much and I hope to learn some things on this forum

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-07-06 : 16:24:03
You can use TOP 500 to get 500 rows back.

If you are instead asking about paging at 500 rows at a time, then make sure you check out ROW_NUMBER() function in BOL.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dave1nc
Starting Member

2 Posts

Posted - 2011-07-06 : 16:26:57
I just to see 500 employees at a time, kind like a range or count based on the current SQL returning 4488 rows. The import can't handle that many at one time.

Dave
Go to Top of Page
   

- Advertisement -