Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Using 'Top' in an update statement


Message #1 by "Davo" <Davo@s...> on Wed, 28 Feb 2001 11:40:00 -0500
> I'd like to update the top 500 records only in a table. It 
> would be helpful to understand if this clause can be used in 
> an update statement, and the syntax for using a specified 
> number as well as a percentage.
> 

this one will update the top 5 percent:

update orderid 
set shipvia=1
from orders o1
where 5>
(100*(cast((select count(*) from orders where orderdate<o1.orderdate) as
real)/
cast((select count(*)from orders) as real)))

  Return to Index