August 8, 2005 at 4:08 pm
How do you update the top 10 in sql 2000?
Heare is what I have so far, but it updates all the records in the table instead of just the top 10 for example:
UPDATE table_info
SET q_active = '1'
FROM (SELECT DISTINCT TOP 10 q_active FROM table_info)
AS q_temp
WHERE table_info.q_active = '0'
August 8, 2005 at 4:24 pm
I don't know your table definition.
But do you have a primary key on the table?
if so
UPDATE table_info
SET q_active = '1'
WHERE table_info.pkfield in (select top 10 pkField from table_info where table_Info.q_active = 0)
August 8, 2005 at 4:27 pm
There is no primary key attached to the table
August 8, 2005 at 4:36 pm
This works great, but is there also a way for it to keep updating 10 more fields everytime it is run?
August 8, 2005 at 5:05 pm
hmm, if there is no primary key on table then how did that work?
If you continue to run that query over and over it will eventually update all rows.
if you want, post your table definition and some sample data, and tell us why you want to update 10 rows at a time, every time you run it?
http://www.aspfaq.com/etiquette.asp?id=5006
begin
UPDATE table_info
SET q_active = '1'
WHERE table_info.pkfield in (select top 10 pkField from table_info where table_Info.q_active = 0)
end
August 8, 2005 at 5:42 pm
Thank you! it's working. The reason I need to update a little bit at a time is because I already have a table with info in it, and I only want to display a small portion of it at a time.
August 9, 2005 at 7:12 am
Hi,
The same is possible with simple Set RowCount
Set rowcount 10
UPDATE table_info
SET q_active = '1'
WHERE table_info.pkfield in (select top 10 pkField from table_info where table_Info.q_active = 0)
Thanks,
Murthy.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply