0

I have a simple script that is returning data from an XML column.

 SELECT 
 CONVERT(XML,[DATA]).value('(/FormSection/FormSection/Form/Breathing/SmokingStatus/node())[1]', 'nvarchar(max)') [SMOKING STATUS]
 FROM MYTABLE

Which works completely fine when a value has been recorded textually like below and the value non-smoker is returned to the grid:

 <SmokingStatus points="null" code="nonSmoker">non smoker</SmokingStatus>

However when I find values like false or true like in the xml below, its returning NULL

 <RequestCessationYes value="false" />

Could anyone point out what I am missing please?

1 Answer 1

1

You need to use the @ symbol prior to the element's name to get values like that:

SELECT V.X.value('(RequestCessationYes/@value)[1]','varchar(5)') AS [value]
FROM (VALUES(CAST('<RequestCessationYes value="false" />' AS xml)))V(X);
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.