您的位置:首页 > 数据库

Sqlserver根据某字段分隔符将一条记录拆分为多行记录

2016-12-05 18:31 591 查看
参考地址:http://blog.sina.com.cn/s/blog_b3eabfd30102wldv.html

参考语句:

if object_id('[aaa]') is not null drop table [aaa]
go
create table [aaa]([地区] varchar(4),[内容] varchar(45))
insert [aaa]
select '中国','021sp.html|管材|4355;028sp.html|建筑材料|3209' union all
select '中国','023sp.html|材|4356;025sp.html|建|9209'
go

select  a.地区,
 内容=substring(a.内容,b.number,charindex(';',a.内容+';',b.number)-b.number)
from [aaa] a
join master..spt_values b on b.type='P'
where charindex(';',';'+a.内容,b.number)=b.number
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐