sql - Update top 50 rows from other table -


how can top 50 rows table , update them table id's (rows) may not exist in second, 'to update', table?

by top 50 mean 50 locations (asc) not in cyclecount table already, background: store 50 locations (per update) in table cyclecount. locations exist, populated in table warehouse. everytime, i'd add 50 new locations warehouse cyclecount, updated locations need in ascending order (of warehouse location)

i have tried using update top (50) table1 set ... etc. doesn't work in case.

i have code, update locations (rows) instead of top 50 (new) locations:

declare @n int  set @n = 50 update cyclecount set magloc   = items.userfield_06,      itemcode = items.itemcode,     ccdate   = getdate() warehouse left outer join items on warehouse.location = items.userfield_06 warehouse.location not in (select magloc cyclecount)  go 

you can work with key word:

;with query (     select top 50 *     [your query] ) update query set magloc   = items.userfield_06,      itemcode = items.itemcode,     ccdate   = getdate() 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -