DECLARE
@xml VARCHAR(MAX)=‘磨毛:1
缩率:2
干磨:3
湿摩:4
水洗牢度:5
手感:6
防水:7
PH:8
日晒:9‘
SET @xml= ‘<root>‘+CHAR(10)+‘<r><v>‘+REPLACE(REPLACE(@xml,CHAR(10),‘</v1></r>‘+CHAR(13)+‘<r><v>‘),‘:‘,‘</v><v1>‘)+‘</v1></r>‘+CHAR(10)+‘</root>‘
BEGIN TRY
DECLARE
@xml2 XML= @xml
SELECT * FROM(
SELECT t.v.query(‘.‘).value(‘/r[1]/v[1]‘,‘varchar(50)‘) as gy,
t.v.query(‘.‘).value(‘/r[1]/v1[1]‘,‘varchar(50)‘) as gyyq
FROM @xml2.nodes(‘/root/r‘)t(v)) a
PIVOT(MAX(gyyq) FOR gy IN ([磨毛],[缩率],[干磨],[湿摩],[水洗牢度],[手感],[防水],[PH],[日晒])) AS pvt
END TRY
BEGIN CATCH
IF @@ERROR>0
SELECT NULL AS [磨毛],NULL AS [缩率],NULL AS [干磨],NULL AS [湿摩],NULL AS [水洗牢度],NULL AS [手感],NULL AS [防水],NULL AS [PH],NULL AS [日晒]
,ERROR_MESSAGE()
END CATCH
--这里展示的是多列的情况