SQL Server一个字符串根据某指定字符 拆分多行显示

逻辑:先将该字段值统一替换为符号(我用的符号是“я”) 分割,再将符号分割替换转为XML数据类型,再利用xml转为多个行

 

拆分前

select ptypeid,serial  from salebill

 

 

拆分后

select ptypeid,serial
from ( select ptypeid, convert(xml, '<n>' + replace(replace(Serial, 'я', 'я'), 'я', '</n><n>') + '</n>') as xmlval1
from salebill ) a
cross apply ( select k.n.value('.', 'nvarchar(800)') serial
from a.xmlval1.nodes('n') k(n) ) bs

 

 

 

posted @ 2022-12-14 20:44  KyrieLee  阅读(865)  评论(0编辑  收藏  举报