[AccessD] Use a select in an update statement

Stuart McLachlan stuart at lexacorp.com.pg
Wed Aug 5 17:46:23 CDT 2009


This won't work before 2005.- before then you couldn't use an expression for TOP:

declare @topnumber int
declare @NoKids int

set @topnumber = 10000
set @NoKids = 2

update tblOrderData
set keycode = 'KEYA'
where RandomNumber in
(Select top (@topnumber) RandomNumber
 From tblOrderData
Where NoChildren = @NoKids and Keycode is null
Order By RandomNumber)

On 5 Aug 2009 at 18:31, jwcolby wrote:

> Ooops, sorry, SQL Server 2005.
> 
> John W. Colby
> www.ColbyConsulting.com
> 
> 
> Stuart McLachlan wrote:
> > Jet SQL or SQL Server?
> > 
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com


Stuart McLachlan




More information about the AccessD mailing list