当前位置: 首页 > 图文教程 > 数据库 > MSSQL > 在SQL2000查询中使用XDR的例子

MSSQL
使用SQL Server索引视图来提高性能
步骤指南:移植SQL 2000 DTS到SSIS
怎样使你的SQL运行得更加灵活和高效
优化SQL Server数据库服务器内存配置
SQL SERVER优化建议
请注意那些容易被忽略的SQL注入技巧
SQL Server 2005密码安全追踪与存储
sql2000下 分页存储过程
SQL Server数据库安全管理经验谈
测试SQL Server的业务规则链接方法
SQL Server的有效安装
SQL Server灾难恢复:重创历史性数据
SQL Server2005发布元年 微软正身企业级应用
MS SQL "1813"错误产生的原因及解决
收藏几段SQL Server语句和存储过程
SQL Server 2005中的备份和恢复增强
如何用SQL Server查询累计值
浅析如何掌握SQL Server的锁机制
步骤指南:测试MSSQL有没有特洛伊木马
手工卸载SQL Server 2000数据库

MSSQL 中的 在SQL2000查询中使用XDR的例子


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 48 ::
收藏到网摘: n/a

  XDR不会不知道吧?就是简化的XML-Data啦。现在示范一个如何实现这样的查询

SELECT o.OrderID, o.OrderDate from Orders o, Customers c,

WHERE o.CustomerID = c.CustomerID and c.CompanyName = ?

Code:

<%@ Language=VBScript %>

<%

    Dim sConn

    sConn = "Provider=SQLOLEDB; Data Source=(local); Initial Catalog=Northwind; User ID=SA;Password=;"

   

    Dim adoConn

    Set adoConn = Server.CreateObject("ADODB.Connection")

    adoConn.ConnectionString = sConn

    adoConn.CursorLocation = 3 'adUseClient

    adoConn.Open

   

    Dim adoCmd

    Set adoCmd = CreateObject("ADODB.Command")

    Set adoCmd.ActiveConnection = adoConn

    adoCmd.CommandText = "Customer[@CompanyName=""Tortuga Restaurante""]"

    adoCmd.Dialect = "{ec2a4293-e898-11d2-b1b7-00c04f680c56}"

   

    adoCmd.Properties("Mapping Schema") = "Orders.xml"

    adoCmd.Properties("Base Path") = "C:\INETPUB\WWWROOT\PBA\"

    adoCmd.Properties("Output Stream") = Response

   

    Response.write "<XML ID='MyDataIsle'>"

    adoCmd.Execute , , 1024 'adExecuteStream

    Response.write "</XML>"

%>



Result:

<XML ID="MyDataIsle">

<Customer CustomerID="TORTU" CompanyName="Tortuga Restaurante">

  <Order CustomerID="TORTU" OrderID="10276" OrderDate="1996-08-08T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10293" OrderDate="1996-08-29T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10304" OrderDate="1996-09-12T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10319" OrderDate="1996-10-02T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10518" OrderDate="1997-04-25T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10576" OrderDate="1997-06-23T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10676" OrderDate="1997-09-22T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10842" OrderDate="1998-01-20T00:00:00" />

  <Order CustomerID="TORTU" OrderID="10915" OrderDate="1998-02-27T00:00:00" />

  <Order CustomerID="TORTU" OrderID="11069" OrderDate="1998-05-04T00:00:00" />

</Customer>

</XML>  



Orders.xml

<?xml version="1.0" ?>

<Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes"

xmlns:sql="urn:schemas-microsoft-com:xml-sql">

  <ElementType name="Order" sql:relation="Orders">

    <AttributeType name="CustomerID" />

    <AttributeType name="OrderID" />

    <AttributeType name="OrderDate" />



    <attribute type="CustomerID" sql:field