declare @x xml
set @x = '<Root>
<row id="1"><name>Larry</name><oflw>some text</oflw></row>
<row id = "2"><name>moe</name></row>
<row id = "3"/>
</Root>'
select T.c.query(..) as result from @x.nodes('/Root/row') T(C)
select T.c.query(..) as result from @x.nodes('/Root/row') T(C)
我收到了以下错误。
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ')'.
任何人都可以帮我纠正错误。我是sql的新手。
答案 0 :(得分:1)
应该是这个:
select T.c.query('..') as result from @x.nodes('/Root/row') T(C)
或者
select T.c.query('.') as result from @x.nodes('/Root/row') T(C)
query
方法的路径参数应为字符串
答案 1 :(得分:0)
不确定您尝试从XML中提取 - 但尝试此查询 - 它将“拆分”存储在XML中的所有信息并将其显示为单独的值:
declare @x xml
set @x = '<Root>
<row id="1"><name>Larry</name><oflw>some text</oflw></row>
<row id="2"><name>moe</name></row>
<row id="3"/>
</Root>'
select
T.c.value('@id', 'int') as 'ID',
T.c.value('(name)[1]', 'varchar(25)') as result,
T.c.value('(oflw)[1]', 'varchar(25)') as 'OFlw'
from @x.nodes('/Root/row') T(C)
输出:
ID result OFlw
1 Larry some text
2 moe NULL
3 NULL NULL