请教下各位
select a from b 返回的结果如下
11,12,13
12,13,14
21,22,23,24,25
39,40,41,42,43,44
11,12
我想把这里的数值都各增加100,更新后的结果如下
111,112,113
112,113,114
121,122,123,124,125
麻烦哪位帮忙写些语句,谢谢
------解决方案--------------------
- SQL code
--先拆分,相加,再合并,再更新if object_id('tb') is not null drop table tbgocreate table tb( col varchar(30))goinsert into tbselect '11,12,13' union allselect '12,13,14' union allselect '21,22,23,24,25' union allselect '39,40,41,42,43,44' union allselect '11,12'gowith cte as( select col,addcol=substring(col,number,charindex(',',col+',',number)-number)+100 from tb a cross join master..spt_values b where type='p' and number between 1 and len(col) and substring(','+col,number,1)=',')update tb set col=b.col2 from tb a inner join ( select col,col2=stuff((select ','+ltrim(addcol) from cte where col=t1.col for xml path('')),1,1,'') from cte t1 group by col) b on a.col=b.colgoselect * from tb/*col------------------------------111,112,113112,113,114121,122,123,124,125139,140,141,142,143,144111,112(5 行受影响)*/