September 29, 2011 at 2:53 am
Hi All
Iam getting the following error while trying to split the xml :
declare @XML xml
set @XML =N'<ReturnMessage id="3655041356">
<AdC ocean="PACCGL">4815044</AdC>
<MessageStatus code="100" time="2011-09-26 01:43:20">status ok</MessageStatus>
<MessageData>700A20000018C0375494400000</MessageData>
<Flags les="0" app="0" />
</ReturnMessage>'
SELECT SUBSTRING(Original, 1, 1) + '-' + SUBSTRING(Original, 2, 2) + '-' + SUBSTRING(Original, 4, 2) + '-' + SUBSTRING(Original, 6, 8) + '-' + SUBSTRING(Original, 14, 8) + '-' + SUBSTRING(Original, 22, 5)
FROM (SELECT @XML.value('/ReturnMessage/MessageData/text()[1]', 'VARCHAR(100)') AS Original) AS d
Error : Msg 2389, Level 16, State 1, Line 9
XQuery [value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'
Kindly help me on the same
September 29, 2011 at 3:07 am
DECLARE @XML XML
SET @XML = N'<ReturnMessage id="3655041356">
<AdC ocean="PACCGL">4815044</AdC>
<MessageStatus code="100" time="2011-09-26 01:43:20">status ok</MessageStatus>
<MessageData>700A20000018C0375494400000</MessageData>
<Flags les="0" app="0" />
</ReturnMessage>'
SELECT SUBSTRING(Original, 1, 1) + '-' + SUBSTRING(Original, 2, 2) + '-' + SUBSTRING(Original, 4, 2) + '-' + SUBSTRING(Original, 6, 8) + '-' + SUBSTRING(Original, 14, 8) + '-' + SUBSTRING(Original, 22, 5)
FROM (
SELECT @XML.value('(/ReturnMessage/MessageData/text())[1]', 'VARCHAR(100)') AS Original
) AS d
September 29, 2011 at 3:11 am
Thanks a lot, it worked for me and saved my time. 🙂
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply