WEB开发网
开发学院数据库MSSQL Server SQLXML系列之一:SQLXML初体验——用XML代替SQL来... 阅读

SQLXML系列之一:SQLXML初体验——用XML代替SQL来操作数据库

 2008-12-06 10:16:03 来源:WEB开发网   
核心提示: <?xml version='1.0' encoding="utf-8" ?><orders xmlns:sql="urn:schemas-microsoft-com:xml-sql"><order id

<?xml version='1.0' encoding="utf-8" ?>
<orders xmlns:sql="urn:schemas-microsoft-com:xml-sql">
 <order id="1" date="2007-03-21T00:00:00" supplier="Dell Coporation">
  <product id="1" name="PC" price="7000" quantity="25"/>
  <product id="2" name="Laptop" price="13000" quantity="50"/>
 </order>
 <order id="2" date="2007-03-23T00:00:00" supplier="HP Coporation">
  <product id="3" name="PC" price="8000" quantity="30"/>
  <product id="4" name="Printer" price="3000" quantity="5"/>
 </order>
 <order id="3" date="2007-03-25T00:00:00" supplier="AA Coporation">
  <product id="5" name="Pencil" price="0.4" quantity="3000"/>
 </order>
</orders>

3. 创建用于查询的Template文件。

基于SQL的查询——Template/Order_Sql.xml

<?xml version="1.0" encoding="utf-8" ?>
<orders xmlns:sql="urn:schemas-microsoft-com:xml-sql">
 <sql:header>
  <sql:param name="orderID" >1</sql:param>
 </sql:header>
 <sql:query>
  SELECT  1 AS TAG,
  0 AS PARENT,
  dbo.T_ORDER.ORDER_ID AS [order!1!id],
  dbo.T_ORDER.ORDER_DATE AS [order!1!date],
  dbo.T_ORDER.SUPPLIER AS [order!1!supplier],
  NULL as [product!2!id],
  NULL as [product!2!name],
  NULL as [product!2!price],
  NULL as [product!2!quantity]
  FROM dbo.T_ORDER
  WHERE dbo.T_ORDER.ORDER_ID = @orderID OR @orderID =0
  UNION ALL
  SELECT
  2 AS TAG,
  1 AS PARENT,
  dbo.T_ORDER.ORDER_ID ,
  dbo.T_ORDER.ORDER_DATE,
  dbo.T_ORDER.SUPPLIER,
  dbo.T_ORDER_DETAIL.PRODUCT_ID,
  dbo.T_ORDER_DETAIL.PRODUCT_NAME,
  dbo.T_ORDER_DETAIL.UNIT_PRICE,
  dbo.T_ORDER_DETAIL.QUANTITY
  FROM
  dbo.T_ORDER INNER JOIN dbo.T_ORDER_DETAIL
  ON dbo.T_ORDER.ORDER_ID = dbo.T_ORDER_DETAIL.ORDER_ID
  WHERE dbo.T_ORDER.ORDER_ID = @orderID OR @orderID =0
  ORDER BY [order!1!id],[product!2!id]
  FOR XML EXPLICIT
 </sql:query>
</orders>

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:SQLXML 系列 之一

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接