0

Here i've a xml in a table 'Test' as below

Id     Input
------------------------------------------------------
1      <DeviceList xmlns="www.domain.com/devicelist">
         <Device xmlns="" Name="Device1">1</Device>
         <Device xmlns="" Name="Device2">2</Device>
       </DeviceList>

2      <DeviceList xmlns="www.domain.com/devicelist">
         <Device xmlns="" Name="Device3">3</Device>
         <Device xmlns="" Name="Device4">4</Device>
       </DeviceList>

3      <DeviceList>
         <Device>4</Device>
         <Device>5</Device>
       </DeviceList>

my expected result would be as below,

Id   DeviceIds
--------------
1    1,2
2    3,4
3    4,5

My query,

SELECT Id, 
STUFF((SELECT 
', ' + CAST(Id.query('./text()') as VARCHAR(MAX)) FROM Input.nodes('/DeviceList/Device') AS Projectors(Id) FOR XML PATH('')), 1, 1, '') AS DeviceIds
FROM test;

But, this query return below result,

Id  DeviceIds
-------------
1   NULL
2   NULL
3   4,5

Anybody help/suggest me on this.

cgsabari
  • 506
  • 2
  • 7
  • 28

1 Answers1

1

Judging by the following question query XML while ignoring namespace?

It looks like /*:tagname might help.

If that does not work this question also provided another work around Ignore XML namespace in T-SQL

But it would require a little knowledge before of the namespace.

Community
  • 1
  • 1
canpan14
  • 1,181
  • 1
  • 14
  • 36