Get XML nodes from SQL Server column as comma-separated list

前端 未结 2 672
青春惊慌失措
青春惊慌失措 2021-01-03 01:20

I have a data stored in a xml column and need a comma-separated list of child nodes. Using script below, I can only get \"A B C\". Please help me get \"A,B,C\" using xquery

相关标签:
2条回答
  • 2021-01-03 01:58

    Try this:

    SELECT
        STUFF((SELECT 
                  ',' + fd.v.value('(.)[1]', 'varchar(10)')
               FROM 
                  Temp12345
               CROSS APPLY
                  col1.nodes('/fd/field/v') AS fd(v)
               FOR XML PATH('')
              ), 1, 1, '')
    

    This gives me A,B,C - does it work for you, too?

    0 讨论(0)
  • 2021-01-03 02:01

    In a full complain XQuery processor you could use just:

    (/fd/field[@i=22])[1]/string-join(*,',')
    
    0 讨论(0)
提交回复
热议问题