礼拜五,送佛到西天 working version of sample code

回答: It's easy胡说之2010-11-19 09:48:44

use my_db;

SET QUOTED_IDENTIFIER ON

DECLARE @xmlLocations XML
SELECT  @xmlLocations = BulkColumn
FROM    OPENROWSET(BULK '\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('//tag1') AS x ( my_tab )

---

Replace all the variables starting with my_ to fit your needs.

所有跟帖: 

there'd be back slash between my_path and my_file, wxc chopped i -胡说之- 给 胡说之 发送悄悄话 胡说之 的博客首页 (0 bytes) () 11/19/2010 postreply 12:20:46

这个佛只走了一半的路,太笨了,Please 继续送! Thanks! -greentree2010- 给 greentree2010 发送悄悄话 (210 bytes) () 11/19/2010 postreply 13:31:37

老胡,we are looking at you! Please扶上马,再送一程!hiahia -veggiedoggie- 给 veggiedoggie 发送悄悄话 veggiedoggie 的博客首页 (0 bytes) () 11/19/2010 postreply 13:39:04

菜菜子有闲,跟着偷艺 -胡说之- 给 胡说之 发送悄悄话 胡说之 的博客首页 (0 bytes) () 11/19/2010 postreply 13:56:16

我不用SQL Server啊,所以就只能起哄了呗:) -veggiedoggie- 给 veggiedoggie 发送悄悄话 veggiedoggie 的博客首页 (134 bytes) () 11/19/2010 postreply 14:14:40

回复:这个佛只走了一半的路,太笨了,Please 继续送! Thanks! -胡说之- 给 胡说之 发送悄悄话 胡说之 的博客首页 (288 bytes) () 11/19/2010 postreply 13:45:56

回复:回复:这个佛只走了一半的路,太笨了,Please 继续送! Thanks! -greentree2010- 给 greentree2010 发送悄悄话 (2431 bytes) () 11/19/2010 postreply 14:21:17

以笔名雷同的XML为例 -胡说之- 给 胡说之 发送悄悄话 胡说之 的博客首页 (1746 bytes) () 11/19/2010 postreply 15:17:43

请您先登陆,再发跟帖!