0

I am using the following code It is not returning me results. What am i missing here?

    declare @iDoc INT           
  EXEC sp_xml_preparedocument @iDoc OUTPUT, '<Ids><Id Val ="40041">11</Id><Id Val ="40042">22</Id></Ids>'   
  Select @iDoc       
  Select Val FROM OPENXML (@iDoc, '/Ids/Id',2) WITH (Val varchar(10))    

2 Answers 2

1

Found answer - Replace '/Ids/Id',2 with '/Ids/Id',5

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

Comments

1

I prefer to use xpath in the WITH part of the query. This way, you don't need to worry about the 3rd parameter of the OPENXML function. The following code works regardless of the 3rd parameter (it can be any value).

declare @iDoc INT           

EXEC sp_xml_preparedocument @iDoc OUTPUT, '<Ids><Id Val ="40041">11</Id><Id Val ="40042">22</Id></Ids>'   

Select *
FROM   OPENXML (@iDoc, '/Ids/Id',2) 
WITH   (Val varchar(10) '@Val', 
       Id int '.')

EXEC sp_xml_removedocument @iDoc

Comments

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.