1、列转多行场景
表中的某个字段是由多个字符串拼接而成,需要按照每个拼接的字符串转换成多行,比如 :【手机品牌】字段里的内容是 小米,华为,苹果;按照这个几个类别进行分组;
2、示例
--原始数据
select ReportingObject,TargetID,ReportDate,Id
from dbo.ReportingInformation
where IsValid=1
and ReportingObject in(1,4)
group by ReportingObject,TargetID,ReportDate,Id
--目标数据
select ReportingObject,TargetID,Id, col
from dbo.ReportingInformation a CROSS APPLY dbo.fnSplit(a.ReportDate,',')b
where IsValid=1
and ReportingObject in(1,4)
3、效果