• 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

  • 相关阅读:
    Topo软件
    如何利用多核CPU来加速你的Linux命令 — awk, sed, bzip2, grep, wc等
    Web学习
    测试Web服务接口
    WebService
    记录几个博客
    Oracle日志性能查看
    设计模式
    hdu 1999 不可摸数
    parfor —— matlab 下的并行循环
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/3231345.html
Copyright © 2020-2023  润新知