0

I am using the following code to read OrderId but it is showing only first

DECLARE @InputXMLHandle int
Declare @RequestXml xml = '<Request><OrderStatus>
                                       <OrderId>RSIN10095</OrderId>
                                       <OrderId>RSIN10096</OrderId>
                                    </OrderStatus>
                            </Request>'
EXEC sp_xml_preparedocument @InputXMLHandle OUTPUT, @RequestXml
    
Select *
From OPENXML(@InputXMLHandle,'/Request/OrderStatus')
WITH
(     
    OrderId varchar(50) 'OrderId'
)

1 Answer 1

1

Use full path

DECLARE @InputXMLHandle int
Declare @RequestXml xml = '<Request><OrderStatus>
                                       <OrderId>RSIN10095</OrderId>
                                       <OrderId>RSIN10096</OrderId>
                                    </OrderStatus>
                            </Request>'
EXEC sp_xml_preparedocument @InputXMLHandle OUTPUT, @RequestXml
Select *
From OPENXML(@InputXMLHandle,'/Request/OrderStatus/OrderId')
WITH
(     
    OrderId varchar(50) '.'
)

or using xml methods

Declare @RequestXml xml = '<Request><OrderStatus>
                                       <OrderId>RSIN10095</OrderId>
                                       <OrderId>RSIN10096</OrderId>
                                    </OrderStatus>
                            </Request>';
select t.n.value('.[1]', 'varchar(50)') id
from @RequestXml.nodes('/Request/OrderStatus/OrderId') t(n);
Sign up to request clarification or add additional context in comments.

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.