如何将XML列加载到另一个表中?

时间:2018-04-30 17:47:03

标签: xml tsql

我有一个名为#printer的临时表,其中一个名为XML_LOAD的列是XML类型(附加字段的屏幕截图)

enter image description here

如何将#printer.XML_LOAD字段加载到另一个表中?

提前致谢

1 个答案:

答案 0 :(得分:0)

我确信有比这更优雅的解决方案

    if object_id('tempdb..#init') is not null  begin drop table #init end;
    SELECT PL.RECORD_ID, PL.PRINTER_LEVELS
    INTO #INIT
    FROM PRINT_LOG PL
    WHERE PL.INSTANT_OF_PRI_DTTM BETWEEN '2018-04-26 00:00:00.000' and '2018-04-27 00:00:00.000'


    SELECT F1.RECORD_ID,
     F1.PRINTER_LEVELS,
     O.splitdata 
    FROM
     (
     SELECT *,
     cast('<X>'+replace(F.PRINTER_LEVELS,':','</X><X>')+'</X>' as XML) as         xmlfilter from #INIT F
     )F1
     CROSS APPLY
     ( 
     SELECT fdata.D.value('.','varchar(254)') as splitdata 
     FROM f1.xmlfilter.nodes('X') as fdata(D)) O