Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Convert XML data field to a relational table

$
0
0

Hi

(SSIS 2008)

I have a table with the following structure

CREATE TABLE [dbo].[TimeSeries](
 [TimeSeriesId] [bigint] IDENTITY(1,1) NOT NULL,
 [TimeSeriesEffectiveDate] [datetime] NOT NULL,
 [content] [xml] NOT NULL
)

on which I would like to transform the xml data field into a relational table.

In my Ole DB Source:

SELECT TimeSeriesId, TimeSeriesEffectiveDate, content AS XMLContent
FROM dbo.TimeSeries
WHERE (lastupdate BETWEEN ? AND ?)

the structure of the xml data field is like this:

<TS><values v0="25" v1="25" v2="25" /><qualities v0="4" v1="1" v2="2" /></TS>

To convert this into a tabular form I have an OleDB Command where I will execute this

declare @xmlValues as xml
select @xmlValues = ?;
with V (id, ts, inx, val1) as 
( 
 select 
 ? as id,
 convert(smalldatetime, ?) as ts,
 convert(int, substring(x.value('local-name(.)', 'varchar(255)'), 2, 255)) as inx1,
 convert(decimal(18,4), x.value('.', 'varchar(255)')) as val1
 from @xmlValues.nodes('TS[1]/values[1]/@*') as T(x)
)
, Q(inx, val2) as 
( 
 select 
 convert(int, substring(y.value('local-name(.)', 'varchar(255)'), 2, 255)) as inx,
 convert(decimal(18,4), y.value('.', 'varchar(255)')) as val2
 from @xmlValues .nodes('TS[1]/qualities[1]/@*') as T(y)
) 
select V.id, V.inx, V.val1, Q.val2, DATEADD(hh, V.inx, V.ts) as ts 
from V left outer join Q on V.inx = Q.inx

The problem is the xml field. In the Ole DB command I can see that it is treated as a
Unicode text strean [DT_NTEXT] but if I create an External column of type NTEXT in the Ole DB Command task to hold the xml input I get the error VS_NEEDSNETMETADATA when I execute the task. I have tried to add a Data Conversion task to convert to other data types, but without luck.

What can I do to make this work?

/Paul S


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>