直接上SQL,此实力代码适用于修改数据
--声明变量
declare @i int
declare @max int
declare @groupid int
declare @userId int
set @i=1
select @max= max(Id) from tPersonnelTable
while @i<=@max
begin
if EXISTS(select * from tPersonnelTable where Id = @i)--验证需要修改数据是否存在
begin
--查询数据,将需要搜索的条件及值查询出来
select @groupid = groupid,@userId=userid from tPersonnelTable where userid = @i
set @i = @i+1
--执行修改
update tPersonnelTable1 set userId= @userId where groupid= @groupid
end
end
以上是执行循环修改SQL,欢迎补充其他方法及指错。