横向 纵向

select * from
 (select userid from dbo.Sys_Users_Record group by userid) a
 outer apply
 (select substring(replace(replace(
  (select total from Sys_Users_Record c where userid=a.userid for xml auto)
  ,'<c total="',','),'"/>',''),2,8000) recordid
 ) b
原文地址:https://www.cnblogs.com/andy_tigger/p/1801487.html