收集自网络,方便自己,方便他人

1 if object_id('[aaa]') is not null drop table [aaa] 2 go 3 create table [aaa]([地区] varchar(4),[内容] varchar(45)) 4 insert [aaa] 5 select '中国','021sp.html|管材|4355;028sp.html|建筑材料|3209' union all 6 select '中国','023sp.html|材|4356;025sp.html|建|9209' 7 go 8 9 select a.地区, 10 内容=substring(a.内容,b.number,charindex(';',a.内容+';',b.number)-b.number) 11 from [aaa] a 12 join master..spt_values b on b.type='P' 13 where charindex(';',';'+a.内容,b.number)=b.number 14 15 /** 16 地区 内容 17 ---- --------------------------------------------- 18 中国 021sp.html|管材|4355 19 中国 028sp.html|建筑材料|3209 20 中国 023sp.html|材|4356 21 中国 025sp.html|建|9209 22 23 (4 行受影响) 24 **/

1 select id, len(nr) - len(replace(nr,'a' , '')) from temp