更新时间:2023-02-05 20:34:59
我建议使用 XQuery 接口,而不是相当笨拙的老式 OPENXML 方法:
I would recommend using the XQuery interface, rather than the rather clunky old OPENXML approach:
SELECT
Ppl.Person.value('(@id)[1]', 'int') AS 'ID',
Ppl.Person.value('(firstname)[1]', 'varchar(20)') AS 'First Name',
Ppl.Person.value('(surname)[1]', 'varchar(20)') AS 'Last Name'
FROM
@input.nodes('/people/person') as Ppl(Person)
这是在 SQL Server 2005 及以后版本中执行此操作的首选方式.
This is the preferred way of doing it in SQL Server 2005 and forward.
输出是一样的:
ID First Name Last Name
1 John Doe
2 Mary Jane
但是,如果您不了解 XML 结构,您就无法真正做到这一点......
You can't really do this however, if you don't know the XML structure.....