0

This is my XML parameter that I set to @XMLSave parameter and send to a stored procedure

<ROOT>
   <P>
      <ID>123456789</ID>
      <Name>admin</Name>
    </P>
    <Group>
       <GroupCardID>14</GroupCardID>
    </Group>
</ROOT>

and I try to get ID value with this command

EXEC sp_xml_preparedocument @idoc OUTPUT, @XMLSave

but when I select values return no value

select * 
from OPENXML (@idoc,'/Root/P',2)  With(ID int)

2 Answers 2

1

Try this:

DECLARE @XmlParameter XML = '<ROOT>
   <P>
      <ID>123456789</ID>
      <Name>admin</Name>
    </P>
    <Group>
       <GroupCardID>14</GroupCardID>
    </Group>
</ROOT>'

SELECT
    @XmlParameter.value('(/ROOT/P/ID)[1]', 'int')

I always prefer the native XQuery support over the clunky old OPENXML stuff.....

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

1 Comment

thank you . but this is on old system that i have to fix some problem and cannot change its structure at this time
0

I Found the answer finally: OpenXML parameter is case sensitive : my XML value start with "ROOT" and openxml parameter was "Root"

1 Comment

yes i do. but i am working on project that was developed before me. and have to fix through OPENXML.

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.