update t set t.ModuleID = a.ModuleID, t.CurrentPlace =a.CurrentPlace from useronline t,(select top 20 * from quan_Board ) as a where t.ID = a.ID
declare @t table(ID int,userid int,UserName varchar(10),moduleID int,CurrentPlace varchar(10),time varchar(10)) declare @a table(ID int,moduleID int,CurrentPlace varchar(10))insert into @t select 1,1,'qq',1331,'ee','ee' insert into @t select 2,2,'aa',13,'e','3g' insert into @t select 4,11,'rr',135,'g','g' insert into @t select 6,13,'gg',14,'gt','y' insert into @t select 7,14,'ee',13,'bh','r'insert into @a select 1,null,null insert into @a select 2,null,null insert into @a select 4,null,null insert into @a select 8,null,null insert into @a select 7,null,nullupdate a set a.moduleID=b.moduleID,a.CurrentPlace=b.CurrentPlace from @a a,(select top 2 ID,moduleID,CurrentPlace from @t order by newid())b where a.id=b.id select * from @a--这样吗?由于数据数量问题,top后面我写的2,测试时改为20即可
set t.ModuleID = a.ModuleID,
t.CurrentPlace =a.CurrentPlace
from useronline t,(select top 20 * from quan_Board ) as a
where t.ID = a.ID
declare @a table(ID int,moduleID int,CurrentPlace varchar(10))insert into @t select 1,1,'qq',1331,'ee','ee'
insert into @t select 2,2,'aa',13,'e','3g'
insert into @t select 4,11,'rr',135,'g','g'
insert into @t select 6,13,'gg',14,'gt','y'
insert into @t select 7,14,'ee',13,'bh','r'insert into @a select 1,null,null
insert into @a select 2,null,null
insert into @a select 4,null,null
insert into @a select 8,null,null
insert into @a select 7,null,nullupdate a set a.moduleID=b.moduleID,a.CurrentPlace=b.CurrentPlace from @a a,(select top 2 ID,moduleID,CurrentPlace from @t order by newid())b where a.id=b.id
select * from @a--这样吗?由于数据数量问题,top后面我写的2,测试时改为20即可