USE CSOS_NEW_2
GO --(1)定义临时表
DECLARE @table TABLE(id INT IDENTITY(1,1),XMLDetail XML)
DECLARE @xml XML
SET @xml='<EBPCaseDetailType>
<openReason xmlns="http://www.ebay.com/marketplace/resolution/v1/services">Item not received</openReason>
<decisionReason xmlns="http://www.ebay.com/marketplace/resolution/v1/services">11002</decisionReason>
<decisionDate xmlns="http://www.ebay.com/marketplace/resolution/v1/services">2013-06-25T18:09:19Z</decisionDate>
<decision xmlns="http://www.ebay.com/marketplace/resolution/v1/services">SELLER_FAULT</decision>
<FVFCredited xmlns="http://www.ebay.com/marketplace/resolution/v1/services">false</FVFCredited>
<notCountedInBuyerProtectionCases xmlns="http://www.ebay.com/marketplace/resolution/v1/services">false</notCountedInBuyerProtectionCases>
<globalId xmlns="http://www.ebay.com/marketplace/resolution/v1/services">EBAY_UK</globalId>
<responseHistory xmlns="http://www.ebay.com/marketplace/resolution/v1/services">
<author>
<role>EBAY</role>
</author>
<activity>agentResolve</activity>
<creationDate>2013-06-25T18:10:03Z</creationDate>
</responseHistory>
<responseHistory xmlns="http://www.ebay.com/marketplace/resolution/v1/services">
<author>
<role>BUYER</role>
</author>
<activity>contactCustomerSupport</activity>
<creationDate>2013-06-25T12:24:53Z</creationDate>
</responseHistory>
<responseHistory xmlns="http://www.ebay.com/marketplace/resolution/v1/services">
<author>
<role>EBAY</role>
</author>
<activity>systemExpireGrace</activity>
<creationDate>2013-06-24T16:01:13Z</creationDate>
</responseHistory>
<responseHistory xmlns="http://www.ebay.com/marketplace/resolution/v1/services">
<note>Nothing has yet been received, if the item can be sent this week then please send it. If not then a refund please. Thankyou</note>
<author>
<role>BUYER</role>
</author>
<activity>create</activity>
<creationDate>2013-06-17T05:34:49Z</creationDate>
</responseHistory>
<agreedRefundAmount xmlns="http://www.ebay.com/marketplace/resolution/v1/services">0</agreedRefundAmount>
<paymentDetail xmlns="http://www.ebay.com/marketplace/resolution/v1/services">
<moneyMovement id="M.1">
<type>REFUND</type>
<fromParty>
<role>SELLER</role>
</fromParty>
<toParty>
<role>BUYER</role>
</toParty>
<amount currencyId="GBP">4.19</amount>
<paymentMethod>PAYPAL</paymentMethod>
<paypalTransactionId>5NE10254S0169263L</paypalTransactionId>
<status>SUCCESS</status>
<transactionDate>2013-06-25T18:09:18Z</transactionDate>
</moneyMovement>
</paymentDetail>
<detailStatus xmlns="http://www.ebay.com/marketplace/resolution/v1/services">4</detailStatus>
<initialBuyerExpectation xmlns="http://www.ebay.com/marketplace/resolution/v1/services">103</initialBuyerExpectation>
</EBPCaseDetailType>'; --(2)创建测数据
INSERT @table (XMLDetail )
VALUES (
@xml -- XMLDetail - xml
) SELECT *
FROM @table --(3)读取XML字段的数据
;
WITH XMLNAMESPACES('http://www.ebay.com/marketplace/resolution/v1/services' AS xs)
SELECT id,XMLDetail.value('(EBPCaseDetailType/xs:paymentDetail/xs:moneyMovement/xs:type)[1]','nvarchar(max)') AS 'Paymentype',
XMLDetail.value('(EBPCaseDetailType/xs:paymentDetail/xs:moneyMovement/xs:fromParty/xs:role)[1]','nvarchar(max)') AS 'Refundrole',
XMLDetail.value('(EBPCaseDetailType/xs:paymentDetail/xs:moneyMovement/xs:paypalTransactionId)[1]','nvarchar(max)') AS 'paypalTransactionId',
XMLDetail.value('(EBPCaseDetailType/xs:openReason)[1]','nvarchar(max)') AS 'openReason'
FROM @table

显示结果如下:

id  Paymentype  Refundrole    paypalTransactionId    openReason
1   REFUND       SELLER         5NE10254S0169263L  Item not received

  

SQL读取XML字段类型的信息的更多相关文章

  1. sql server sql查询数据库的表,字段,主键,自增,字段类型等信息

    1.查询数据表的属性(名称.说明.是否主键.数据类型.是否自增) SELECT t1.name columnName,case when t4.id is null then 'false' else ...

  2. SQL Server数据库字段类型说明

    SQL Server数据库字段类型说明 目前Sql Server 数据库一共有X个字段类型,大体分为9类,分别是字符串类型.二进制码字符串数据类型.Unincode字符串数据.整数类型.精确数据类型. ...

  3. 修改SQL数据库中表字段类型时,报“一个或多个对象访问此列”错误的解决方法

    在SQL数据库中使用SQL语句(格式:alter table [tablename] alter column [colname] [newDataType])修改某表的字段类型时,报一下错误:由于一 ...

  4. FIREDAC不能识别SQL的某些字段类型

    FIREDAC不能识别SQL的某些字段类型 经常见有网友有类似的提问:请问各位,在DataSnap中使用SQL数据SUM函数,如果是统计浮点型数值的话,返回是乱码,哪位是什么原因?  其实这不是DAT ...

  5. Oracle使用SQL语句修改字段类型

    Oracle使用SQL语句修改字段类型 1.如果表中没有数据 Sql代码 1 2 3 alter table 表名 modify (字段名1 类型,字段名2 类型,字段名3 类型.....)  alt ...

  6. SQL语句修改字段类型与第一次SQLServer试验解答

    SQL语句修改字段类型 mysql中 alert table name modify column name type; 例子:修改user表中的name属性类型为varchar(50) alert ...

  7. (转)SQL对Xml字段的操作

    T-Sql操作Xml数据 一.前言 SQL Server 2005 引入了一种称为 XML 的本机数据类型.用户可以创建这样的表,它在关系列之外还有一个或多个 XML 类型的列:此外,还允许带有变量和 ...

  8. SQL对Xml字段的操作

    转:http://www.cnblogs.com/youring2/archive/2008/11/27/1342288.html T-Sql操作Xml数据 一.前言 SQL Server 2005 ...

  9. (轉載)sql server xml字段的操作

    原文轉自:http://blog.csdn.net/hliq5399/article/details/8315373 另外可參考:https://msdn.microsoft.com/en-us/li ...

随机推荐

  1. Codeforces 527E Data Center Drama(欧拉回路)

    题意: 给定一个无向图连通图,把这个的无向边变成有向边,并添加最少的有向边使这个图每个结点的出度为偶数. Solution: 题目很长,并且很多条件说的不太直接,确实不太好懂. 首先先看得到的无向图, ...

  2. Float之谜

    先来看几个例子: public class Thirtyfirst1{ public static void main(String[] args){ int i = 2000000000; int ...

  3. C#快速导入海量XML数据至SQL Server数据库

    #region 将Xml中的数据读到Dataset中,然后用SqlBulkCopy类把数据copy到目的表中using (XmlTextReader xmlReader = new XmlTextRe ...

  4. python【第二篇】列表、元组、字典及文件操作

    本节内容 列表 元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1.列表 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作:列表有序.可变.元素 ...

  5. Python Tutorial 学习(十)-- Brief Tour of the Standard Library

    10.1. Operating System Interface os库 import os os.getcwd() # Return the current working directory 'C ...

  6. 已安装好的tengine编译添加未被安装的模块

    nginx -V 可以查看原来编译时都带了哪些参数 原来的参数: --prefix=/usr/local/tengine 需添加的参数: --with-http_stub_status_module ...

  7. SSH三种框架及表示层、业务层和持久层的理解

    Struts(表示层)+Spring(业务层)+Hibernate(持久层) SSH:Struts(表示层)+Spring(业务层)+Hibernate(持久层) Struts:Struts是一个表示 ...

  8. Python 更改cmd中的字色

    没有gui的python程序是在cmd窗口中运行的,黑色背景,灰色的字,确实很复古,不符合现代人的使用习惯-同事在用我写的小工具时,清一色的字色,看起来会没有重点性,因此我就想通过更改cmd中的字色来 ...

  9. QVariant(相当于是Java里面的Object,起到一个数据类型“擦除”的作用,可以使用Q_DECLARE_METATYPE进行注册)

    =QVariant= [%这个类型相当于是Java里面的Object,它把绝大多数Qt提供的数据类型都封装起来,起到一个数据类型“擦除”的作用.比如我们的 table单元格可以是string,也可以是 ...

  10. 使用SSH代理上IPV6(使用SSH端口转发)

    这几个月在国外待着,一直担心我的六维账户怎么办,那可是个宝贝啊.我看网上说可以用六飞啊神马的在IPV6下上IPV6的网站,但是冒失现在六维封禁了非学校的IPV6地址,所以这些软件就不顶用了. 想到以前 ...