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
参考语句:
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
相关文章推荐
- Sqlserver根据某字段分隔符将一条记录拆分为多行记录
- 怎么根据一条记录中某个字段的值,将此记录分成多条显示?
- SqlServer-删除某一个字段重复的记录,只保留一条
- oracle 根据时间排序,删除相邻的除排序字段均相同的两条中较新的一条记录
- sqlserver 将一个字段下的多行语句合并成一条数据
- Oracle中将一条记录(某字段中为合并的信息)拆分成多条记录
- Oracle 删除重复数据只留一条 查询及删除重复记录的SQL语句 1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断 select * from 表 wher
- Oracle 删除重复数据只留一条 查询及删除重复记录的SQL语句 1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断 select * from 表 wher
- 在sqlserver中如何根据字段名查找字段所在的表
- SqlServer:根据指定分隔符,把传入字符串分隔处理后,返回数据表,函数功能类似.NET的string.Split()
- Sql ,sqlserver根据一个字段分组查询
- MSSQL批量循环创建新表:根据数据库A中的表A字段的记录值为新表名并创建新表到数据库B中
- 【SQL】根据多行记录的公共属性,将不同类型对应的值合并到一行中
- SQLServer中如何将一个字段的多个记录值合在一行显示
- MySQL数据库将多条记录的单个字段合并成一条记录
- 带分割符号列值记录拆分成多行的实现方式
- 字段查找如何去掉数据库重复记录并且只保留一条记录
- sql server 删除某个字段重复的记录并留下一条记录
- 删除表中多余的重复记录,重复记录是根据单个字段(Id)来判断,只留有rowid最小的记录
- 数据库查询给定字段的多行记录的合并