June 15, 2016 at 2:50 pm
I have a table (Messages) with XML stored as a varchar(max) column (Payload).
The XML is formatted like this:
<NCOAPACP xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="uri://www.gen.da.hob/VC/Contract/QualityManagement/EMSM">
<VID>3656183</VID>
</NCOAPACP>
How do I query the table to get a list of all the values in the VID node? Every time I query using what I thought was the right way, I get a list of null values.
Edit - sorry, I didn't post my actual query. I'm embarrassed as to where I ended up with it.
June 15, 2016 at 3:41 pm
You probably didn't use the namespace.
DECLARE @x TABLE (Payload VARCHAR(max));
INSERT @x (Payload)
VALUES ('<NCOAPACP xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="uri://www.gen.da.hob/VC/Contract/QualityManagement/EMSM">
<VID>3656183</VID>
</NCOAPACP>');
WITH XMLNAMESPACES (DEFAULT 'uri://www.gen.da.hob/VC/Contract/QualityManagement/EMSM')
SELECT nd.value ('./text()[1]','int') AS vid
FROM @x AS x
CROSS APPLY ( -- Convert to XML
SELECT cast(x.Payload AS XML)
) x2(PayloadXml)
-- Get the VID nodes
CROSS APPLY x2.PayloadXml.nodes('NCOAPACP/VID') c(nd)
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
June 15, 2016 at 3:49 pm
Weird. I was using the namespace, but I might have had something wrong with the formatting. Just tried it again and it worked. Thanks!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply