0
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)

I am getting following error.

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ')'.

could any one help me correcting the error. I am new to sql .

1
  • @gbn : i have edited t question. please go through now. Commented Jul 26, 2011 at 12:53

2 Answers 2

1

It should one this:

select T.c.query('..') as result from @x.nodes('/Root/row') T(C)

or maybe

select T.c.query('.') as result from @x.nodes('/Root/row') T(C)

The path parameter to the query method should be a string

Sign up to request clarification or add additional context in comments.

Comments

0

Not sure what you're trying to extract from your XML - but try this query - it will "take apart" all the bits of information stored in the XML and show them as separate values:

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)

Output:

ID  result  OFlw
1   Larry   some text
2   moe     NULL
3   NULL    NULL

3 Comments

Thanks alot. I got know how to use value() method.
Could u please explain me tha usage of node().
It creates an "in-memory" list / pseudo table of XML nodes, based on the XPath provided - here, it creates a list of all <row> nodes in the <Root> parent node. You can then use those to grab individual values from each node, as if it were a table with XML values inside it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.