我可以从SQL Server 2005中的代码中获取第一条记录。如何获取所有这些记录?如果我删除'[1]'索引,我会得到一些单例错误......
declare @xml xml
set @xml =
'<my:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-03-16T20:13:11">
<my:field>test1</my:field>
<my:field>test2</my:field>
<my:field>test3</my:field>
<my:field>test4</my:field>
</my:myFields>'
SELECT @xml.value('declare namespace my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-03-16T20:13:11";
(/my:myFields/my:field)[1]', 'varchar(100)') as test
答案 0 :(得分:0)
declare @xml xml
set @xml =
'<my:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-03-16T20:13:11">
<my:field>test1</my:field>
<my:field>test2</my:field>
<my:field>test3</my:field>
<my:field>test4</my:field>
</my:myFields>'
SELECT Y.ID.value('.', 'varchar(100)') as test
FROM @xml.nodes('declare namespace my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-03-16T20:13:11";
(/my:myFields/my:field)') as Y(ID)