zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    添加日志文件
    C库函数对文件的操作
    getpass的使用
    C语言实现 冒泡排序 选择排序 希尔排序
    批量Ping执行Bash脚本
    Script
    echo
    Centos7 pxe
    Rsync 参数
    Ip HostName查询
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/3231345.html
Copyright © 2011-2022 走看看