Declare @xmlDoc xml
SET @xmlDoc = (SELECT * FROM USERS AS UserTable For XML AUTO, ELEMENTS, ROOT('Root'))
SELECT @xmlDoc Result as below : <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> SelectEmp_Id,Emp_Namefrom tblEmployee WhereEmp_Id<3For XML AUTO,ELEMENTS
--For XML [MODE],ELEMENTS

MODE

AUTO, RAW, EXPLICIT

Result [AUTO]

<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. python和shell间变量互相传递

    Python -> shell: 参考文章 1.环境变量 import os var=123或var=’123’ os.environ[’var’]=str(var) #environ的键值必须 ...

  2. Eclipse中用两个控制台测试网络通信程序

    1.启动发送端和接收端程序,这时在控制台可以看到两个程序在运行,如下图. 2.这种情况下只有一个控制台窗口,不便于测试程序,于是新建一个控制台窗口,如下图. 3.这时可以发现已经有了两个控制台窗口了, ...

  3. loadruner关联web_reg_save_param

    语法int web_reg_save_param(const char *ParamName, <list of Attributes>, LAST); 参数说明: • ParamName ...

  4. Linux内核编译安装

    1. .config 复制一份当前系统编译时的配置,在/usr/src目录下 $ ls /usr/src/ linux-headers-4.10.0-35 linux-headers-4.8.0-36 ...

  5. poj1040 Transportation(DFS)

    题目链接 http://poj.org/problem?id=1040 题意 城市A,B之间有m+1个火车站,第一站A站的编号为0,最后一站B站的编号为m,火车最多可以乘坐n人.火车票的票价为票上终点 ...

  6. Java经典设计模式之十一种行为型模式

    转载: Java经典设计模式之十一种行为型模式 Java经典设计模式共有21中,分为三大类:创建型模式(5种).结构型模式(7种)和行为型模式(11种). 本文主要讲行为型模式,创建型模式和结构型模式 ...

  7. ubuntu调错

    最近运行一个程序,出现错误 ’event.h‘,猜想是缺少event lib 库 于是安装sudo apt-get install libevent-dev 即可.

  8. HTTP缓存了解(一)

    引言 HTTP/1.1 200 OK X-Powered-By: Express Content-Type: text/html; charset=utf-8 Content-Length: 3 ET ...

  9. NumPy 新知

    import numpy as np a = np.arange(5) a array([0, 1, 2, 3, 4]) 增加一个维度: b = a[:, None] c = a[:,np.newax ...

  10. 为什么23种设计模式里面没有MVC?

    作者:lorio链接:https://www.zhihu.com/question/27738109/answer/100241918来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...