Getting multiple records from xml column with value() in SQL Server

前端 未结 3 1859
自闭症患者
自闭症患者 2020-12-10 06:47

This SQL only returns the first Activity element. How do I select them all? If I remove the [1] in the query I get an error that \"value() requires a singleton\".

3条回答
  •  萌比男神i
    2020-12-10 07:06

    Thanks Ed, but I found an easier version:

    SELECT T.C.value('.', 'varchar(100)') as activity
    FROM @myDoc.nodes('(/Root/Activities/Activity)') as T(C)
    

    Though from your "unnecessarily complex" example it seems worryingly simple..

提交回复
热议问题