declare @startId int;
set @startId = 63;
while @startId>0
begin
declare @WriteThis nvarchar(800) ;
set @WriteThis ='';
with f as ( select * from GudingBianpaiDuizhenBiao where ThisZhenDIndex =@startId union all select a.* from GudingBianpaiDuizhenBiao as a inner join f as b on a.MainId=b.ThisZhenDIndex)
select @WriteThis=@WriteThis+honglan+',' from f ----赋值多条数据的字段放到一个变量里
update GudingBianpaiDuizhenBiao set AllInThisDuan =SUBSTRING (@WriteThis,1,LEN(@WriteThis)-1) where Id = @startId;
set @startId= @startId -1 ;
select @startId;
select @WriteThis;
end
sqlserver获取子集,以及多条数据赋值给自定义的变量
于 2023-03-23 20:08:04 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)