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. SGU 159.Self-Replicating Numbers

    时间限制:0.5s 空间限制:6M 题意:         在b(2<b<36)进制中,找到所有长度为n(0<n<2000)的自守数k,满足k^2%b^n=k,字典序输出.   ...

  2. GRUB配置

    参数讲解: default :定义缺省启动的系统 如果安装多系统的话 会有多个title 信息 可以通过设置 default: 来改变启动那个系统 默认第一个为0 第二个为1 依次类推 timeout ...

  3. [Windows] php开发工具,zendstudio13使用方法补丁

    官网原版下载 http://downloads.zend.com/studio ... win32.win32.x86.exe 破解补丁: 链接:http://pan.baidu.com/s/1gdi ...

  4. python学习笔记(一)元组,序列,字典

    python学习笔记(一)元组,序列,字典

  5. Linux服务器集群技术的概述

    目前,越来越多的网站采用Linux操作系统,提供邮件.Web.文件存储.数据库等服务.也有非常多的公司在企业内部网中利用Linux服务器提供这些服务.随着人们对Linux服务器依赖的加深,对其可靠性. ...

  6. input placeholder文字垂直居中(Mobile & PC)

    Html5输入框支持placeholder,但是在定义文本框中定义placeholder存在兼容问题 <input type="text" placeholder=" ...

  7. hibernate spring 事务配置

    <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx: ...

  8. 利用多线程资源竞争技术上传shell

    通过多线程资源竞争的手段同时上传两个头像,就可以在Apache+Rails环境下实现远程代码执行.这并不是天方夜谭,同时我相信许多文件上传系统都会有这个漏洞……这是一个非常有趣的安全实验,一起来看看吧 ...

  9. 马云专访二:点评阿里雅虎交易、BAT三家、互联网巨头与政府关系

    记者:我们不得不要说到你和雅虎之间的事情了.你知道,雅虎对整个互联网业的意义不只是一家公司,它有它象征的意义,重要的是,雅虎对阿里巴巴的意义更加非同寻常,当你最后决定用76亿美元从雅虎“赎身”的时候, ...

  10. hashCode() 和equals() 区别和作用

    HashSet和HashMap一直都是JDK中最常用的两个类,HashSet要求不能存储相同的对象,HashMap要求不能存储相同的键. 那么Java运行时环境是如何判断HashSet中相同对象.Ha ...