1. Declare @xmlDoc xml
    SET @xmlDoc = (SELECT * FROM USERS AS UserTable For XML AUTO, ELEMENTS, ROOT('Root'))
    SELECT @xmlDoc
  2. Result as below :
  3. <Root>
      <UserTable>
        <UserDBID>1</UserDBID>
        <UserID>Admin                           </UserID>
        <UserName>admin</UserName>
        <Password>49CE5FB6D05148ACB66A</Password>
        <FullName />
        <LocalFullName />
        <Title />
        <Department />
        <UserRole>Administrator</UserRole>
        <IsFirstLogin>0</IsFirstLogin>
        <PwdNeverExpire>1</PwdNeverExpire>
        <PwdLastModifyTime>2013-07-10T13:40:48.470</PwdLastModifyTime>
      </UserTable>
      <UserTable>
        <UserDBID>2</UserDBID>
        <UserID>cshsvc                          </UserID>
        <UserName>cshsvc</UserName>
        <Password>54C0FCD2B54CCE8BE6AD</Password>
        <FullName />
        <LocalFullName />
        <Title />
        <Department />
        <UserRole>Administrator</UserRole>
        <IsFirstLogin>0</IsFirstLogin>
        <PwdNeverExpire>1</PwdNeverExpire>
        <PwdLastModifyTime>2013-07-10T13:38:25.070</PwdLastModifyTime>
      </UserTable>
    </Root>
  4. SelectEmp_Id,Emp_Namefrom tblEmployee WhereEmp_Id<3For XML AUTO,ELEMENTS
  5. --For XML [MODE],ELEMENTS

MODE

AUTO, RAW, EXPLICIT

Result [AUTO]

  1. <tblEmployee><Emp_Id>1</Emp_Id><Emp_Name>AAA</Emp_Name></tblEmployee><tblEmployee><Emp_Id>2</Emp_Id><Emp_Name>BBB</Emp_Name></tblEmployee>

Result [RAW]

Above Xml with Instead of <tblEmployee> here..... <ROW> and </tblEmployee> is </ROW>

SELECT ( SELECT 'White' AS Color1,
'Blue' AS Color2,
'Black' AS Color3,
'Light' AS 'Color4/@Special',
'Green' AS Color4,
'Red' AS Color5
FOR
XML PATH('Colors'),
TYPE
),
 ( SELECT 'Apple' AS Fruits1,
'Pineapple' AS Fruits2,
'Grapes' AS Fruits3,
'Melon' AS Fruits4
FOR
XML PATH('Fruits'),
TYPE
)
FOR XML PATH(''),
ROOT('SampleXML')
GO

create xml file from sql script的更多相关文章

  1. persistent.xml hibernate 利用sql script 自定义生成 table 表

    <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http:// ...

  2. LinqToXml (一) Create Xml file By Dom /Linq

    目前,在xml 应用编程领域比较流行的开发模型是W3C 提供的DOM(文档对象模型),在.net Framework 通过命名空间 System.Xml 对该技术提供了支持.随着Linq to XMl ...

  3. Create XML Files Out Of SQL Server With SSIS And FOR XML Syntax

    So you want to spit out some XML from SQL Server into a file, how can you do that? There are a coupl ...

  4. How to Enable Trace or Debug for APIs executed as SQL Script Outside of the Applications ?

    In this Document   Goal   Solution   1: How do you enable trace for an API when executed from a SQL ...

  5. csharp:SMO run sql script

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. [vb.net]XML File Parsing in VB.NET

    Introduction Parsing XML files has always been time consuming and sometimes tricky. .NET framework p ...

  7. How to: Write Object Data to an XML File

    This example writes the object from a class to an XML file using the XmlSerializer class. Namespace: ...

  8. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ex.activity/com.ex.activity.LoginActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ex.activity/com.ex.activity.L ...

  9. SQL SERVER – Import CSV File Into SQL Server Using Bulk Insert – Load Comma Delimited File Into SQL Server

    CSV stands for Comma Separated Values, sometimes also called Comma Delimited Values. Create TestTabl ...

随机推荐

  1. Linux下文件特殊权限

    SUIDSUID表示在所有者的位置上出现了s在一个命令的所有者的权限上如果出现了s,当其他人在执行该命令的时候将具有所有者的权限.SUID权限仅对二进制文件有效 SGID表示在组的位置上出现了s如果一 ...

  2. zookeeper的简单使用

    前言 最近项目中要使用基于zookeeper的集中配置管理系统,而对于zookeeper仅在当初使用阿里开源分布式服务调用框架dubbo时简单的了解一下.本 文的主要目的,调用zkclient (ma ...

  3. LoadRunner监控Linux的三种方法

    方法一.LR + SiteScope/nmon 方法二.使用rstatd包 1.下载rpc.rstatd-4.0.1.tar.gz 2.解压缩 tar -zxvf rpc.rstatd-4.0.1.t ...

  4. 专业的抢票软件 12306bypass

    专业的抢票软件 https://www.12306bypass.com/

  5. ubuntu下让进程在后台运行

    (1)输入命令: nohup 你的shell命令 & (2)回车,使终端回到shell命令行: (3)使用第二第三条,完全屏蔽掉信号 用disown -h jobspec来使某个作业忽略HUP ...

  6. 基于rsync方式的文件备份

    rsync 是一个快速增量文件传输工具,它可以用于在同一主机备份内部的备分,我们还可以把它作为不同主机网络备份工具之用.本文主要讲述的是如何自架rsync服 务器,以实现文件传输.备份和镜像.相对ta ...

  7. Spring MVC——搭建HelloWeb工程

    1.确保环境配置配置正确(Myeclipse(eclipse)+Tomcat) 2.新建web project 3.将Spring MVC所需的jar包粘贴到WebRoot/WEB-INF/lib下 ...

  8. Unity Shader 之 渲染流水线

    Unity Shader 之渲染流水线 什么是渲染流水线 一个渲染流程分成3个步骤: 应用阶段(Application stage) 几何阶段(Geometry stage) 光栅化阶段(Raster ...

  9. Scrapy实战篇(七)之Scrapy配合Selenium爬取京东商城信息(下)

    之前我们使用了selenium加Firefox作为下载中间件来实现爬取京东的商品信息.但是在大规模的爬取的时候,Firefox消耗资源比较多,因此我们希望换一种资源消耗更小的方法来爬取相关的信息. 下 ...

  10. SOJ 4552 [期望,概率]

    题目链接:[http://acm.scu.edu.cn/soj/problem.action?id=4552] 题意:给你n种卡牌,每种卡牌有无限多个,每次从中抽取一张卡牌,问:1.集齐这n种卡牌需要 ...