博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL XML 2
阅读量:7076 次
发布时间:2019-06-28

本文共 1201 字,大约阅读时间需要 4 分钟。

DECLARE 
@Items XML
SET 
@Items 
= 
    
'
<bookstore>
<book category="COOKING">
  <title lang="en">Everyday Italian2</title>
  <author>Giada De Laurentiis</author>
  <year>2005</year>
  <price>30.00</price>
</book>
<book category="CHILDREN">
  <title lang="en">Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>
<book category="WEB">
  <title lang="en">XQuery Kick Start</title>
  <author>James McGovern</author>
  <author>Per Bothner</author>
  <author>Kurt Cagle</author>
  <author>James Linn</author>
  <author>Vaidyanathan Nagarajan</author>
  <year>2003</year>
  <price>49.99</price>
</book>
<book category="WEB">
  <title lang="zh">Learning XML</title>
  <author>Erik T. Ray</author>
  <year>2003</year>
  <price>39.95</price>
</book>
</bookstore>
'
DECLARE 
@tb 
TABLE (
            id 
INT 
IDENTITY(
1 ,
1
PRIMARY 
KEY
           ,title 
NVARCHAR(
100)
           ,author 
NVARCHAR(
100)
           ,
YEAR 
INT
           ,price 
DECIMAL(
10 ,
3)
        )
DECLARE 
@idoc 
INT
EXEC sp_xml_preparedocument 
@idoc OUTPUT,
@Items
INSERT 
INTO 
@tb
SELECT 
*
FROM   OPENXML(
@idoc ,
'
//book
' ,
2)
       
WITH (
           title 
NVARCHAR(
100)
          ,author 
NVARCHAR(
100)
          ,
YEAR 
INT
          ,price 
DECIMAL(
10 ,
3)
       ) 
   
SELECT 
* 
FROM   
@tb

转载于:https://www.cnblogs.com/skydau/archive/2012/08/18/2645900.html

你可能感兴趣的文章
第九周总结
查看>>
173. Binary Search Tree Iterator
查看>>
python_正则表达式匹配ip
查看>>
json数据导出excel
查看>>
Appium 服务器参数
查看>>
Openssl源代码整理学习---含P7/P10/P12说明
查看>>
TP90 95 99指标
查看>>
进度条2
查看>>
程序员能力矩阵 Programmer Competency Matrix
查看>>
java中与运算,或运算,异或运算,取反运算
查看>>
TCP之报文首部格式
查看>>
Docker - 生成镜像
查看>>
RN—Android 物理返回键监听
查看>>
shell日志颜色处理
查看>>
两直线垂直的充要条件
查看>>
Review: Function Pointer
查看>>
*p=&a是把a的值赋给p,p=&a是把a的地址赋给p。
查看>>
input框限制只能输入正整数、字母、小数、汉字
查看>>
SQL Server 之登录
查看>>
21-Python与设计模式--备忘录模式
查看>>