• create xml file from sql script


    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>

    Select
    Emp_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

  • 相关阅读:
    centos7+php7.1.4+mysql5.7+swoole搭建
    鄙视自己(转)
    Mysql的sql优化概念---三大范式
    PHP的设计模式-单例设计
    Composer的安装使用
    PHPstorm的一些快捷键
    论代码走查的重要性
    Java泛型读书笔记 (三)
    Java泛型读书笔记 (一)
    Java泛型读书笔记 (二)
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/3231345.html
Copyright © 2020-2023  润新知