0

I have seen many questions addressing this issue, but unfortunately I still was not able to make it work.

Here's an example of the XML data contained in an XML column called RentalValueAmount in a table called Units:

<X C="1" I="0">
  <E D="1000Y0M0W0D" P="1" A="36500" />
</X>

I tried this but did not get any values:

select 
    cast(RentalValueAmount as XML).value('data(/X/E)[1]','varchar(10)') as test
from dbo.units

I need to extract or return 36500 as a number using a query but I have not been able to do so. Obviously I do not know XML, so I would really appreciate the help.

1 Answer 1

1

Try this:

select 
cast(RentalValueAmount as XML).value('(/X/E)[1]/@A','varchar(10)') as test
from dbo.units

If the column is already of XML data type, you don't need to cast it to XML again.

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

1 Comment

@JasonC There is no need to cast to XML when you already have an XML column.

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.