sql 累加
create table T( [1] varchar(10), [2] varchar(10), [3] varchar(10), [4] varchar(10), x varchar(10));insert into Tselect '0','X','0','2','0'unionselect '1','2','Y','2','0'unionselect '3','X','X','2','0'unionselect '0','Y','1','2','0'declare @i int,@i_column varchar(10)set @i=1set @i_column=''while @i<=4 begin set @i_column='['+cast(@i as varchar(10))+']' update T set x=cast(x as float)+(case when ltrim(rtrim(@i_column))='x' then 1 when ltrim(rtrim(@i_column))='y' then 0.5 else 0 end) set @i=@i+1 end