一列转多列

源数据:
一列转多列

要转换成
一列转多列

解决方案:

SELECT   [1] AS c1,[2] AS c2,[3]
  FROM
  (

  SELECT ROW_NUMBER() OVER(ORDER BY SUBSTR) AS id , *  FROM cis.dbo.mysplit('12-23-34','-')
  ) pvt
  PIVOT
  (
  MAX(pvt.substr) FOR id IN ([1] ,[2],[3])
  ) p



----------------
第二种方案
  select stuff((SELECT ',' + diagnose_info FROM inhos_diagnose AS t WHERE t.inhos_id = 17 and t.pri>0 FOR xml path('')), 1, 1, '')

你可能感兴趣的:(列)