再來一次

XML:

<my_tag1>

  <my_tag2>

    <my_tag3>foo</my_tag3>

    <my_tag4>bar</my_tag4>

  </my_tag2>

</my_tag1>

-------------------------------------------

use my_db;

SET QUOTED_IDENTIFIER ON

DECLARE @xmlLocations XML
SELECT  @xmlLocations = BulkColumn
FROM    OPENROWSET(BULK 'c:/my_path/my_file.xml', SINGLE_BLOB) AS x

INSERT  INTO my_table
        (
        my_col_1,
        my_col_2
        )
        SELECT
            x.my_tag2.value ('my_tag3[1]', 'varchar(50)') AS my_col_1,
            x.my_tag2.value ('my_tag4[1]', 'varchar(50)') AS my_col_2,
        FROM    @xmlLocations.nodes('//my_tag1/my_tag2') AS x ( my_tab )

 

-----

請您先登陸,再發跟帖!