XQuery [nodes()]:&#39; <eof>&#39;附近的语法错误,期望一个步骤表达式</eof>

时间:2015-01-09 16:38:36

标签: sql sql-server sql-server-2008 xpath syntax-error

运行以下SQL / XPath查询会返回以下错误:

查询:

;WITH XMLNAMESPACES (
  'http://schemas.microsoft.com/win/2004/08/events/event' as ns
, default 'http://schemas.microsoft.com/win/2004/08/events/event'
)

select [Events].[Event].value('(./System/TimeCreated/@SystemTime)[1]','nvarchar(100)') EventTime
from @xml.nodes('/*/Event/') [Events]([Event])

错误:

XQuery [nodes()]: Syntax error near '<eof>', expected a step expression.

1 个答案:

答案 0 :(得分:14)

来自:http://www.experts-exchange.com/Database/MS-SQL-Server/Q_27789732.html

问题是xpath末尾的/。即。

from @xml.nodes('/*/Event/') [Events]([Event])

应该是:

from @xml.nodes('/*/Event') [Events]([Event])