Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I want to grab the first 50

Status
Not open for further replies.

wuwang

Programmer
May 16, 2001
48
US
Hi,

I want to grab the first 50 records from the table.
Why this code doesn't work?

declare @COUNT INTEGER
SELECT @COUNT = 0

WHILE @COUNT <= 50
BEGIN
select MIN(TABLE_ID)
from TABLE
@COUNT = @COUNT + 1
END


Thanks for your help.


 
Because sql does not work that way.

SQL 2000

select top 50 table_id from table order by table_id desc

sql 7
set rowcount = 50
select table_id from table order by table_id desc
set rowcount = 0

make sure you reset the rowcount or all your queries will return 50 rows max.



btw. Even is sql did work the way you wanted it to
your code would return the first table_id 50 times not the first 50 table_id(s)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top