OPENXML In SQL Server 2005
2005-04-16 08:31
615 查看
In SQL Server 2000, you can use a varchar, nvarchar, text, or ntext variable to generate a document handle using the sp_xml_preparedocument stored procedure. In SQL Server 2005, you can also use an xml variable, as shown in the following example.
DECLARE @doc xml
SET @doc = '<?xml version="1.0" ?>
<SalesInvoice InvoiceID="1000" CustomerID="123">
<Items>
<Item ProductCode="12" Quantity="2" UnitPrice="12.99"/>
<Item ProductCode="41" Quantity="1" UnitPrice="17.45"/>
<Item ProductCode="2" Quantity="1" UnitPrice="2.99"/>
</Items>
</SalesInvoice>'
DECLARE @docHandle int
EXEC sp_xml_preparedocument @docHandle OUTPUT, @doc
SELECT * FROM
OPENXML(@docHandle, 'SalesInvoice/Items/Item', 1)
WITH
(ProductCode int,
Quantity int,
UnitPrice smallmoney)
EXEC sp_xml_removedocument @docHandle
DECLARE @doc xml
SET @doc = '<?xml version="1.0" ?>
<SalesInvoice InvoiceID="1000" CustomerID="123">
<Items>
<Item ProductCode="12" Quantity="2" UnitPrice="12.99"/>
<Item ProductCode="41" Quantity="1" UnitPrice="17.45"/>
<Item ProductCode="2" Quantity="1" UnitPrice="2.99"/>
</Items>
</SalesInvoice>'
DECLARE @docHandle int
EXEC sp_xml_preparedocument @docHandle OUTPUT, @doc
SELECT * FROM
OPENXML(@docHandle, 'SalesInvoice/Items/Item', 1)
WITH
(ProductCode int,
Quantity int,
UnitPrice smallmoney)
EXEC sp_xml_removedocument @docHandle
相关文章推荐
- Work with XML Data Type in SQL Server 2005 from ADO.NET 2.0
- [转载]官方视频教学《XML Support in SQL Server 2005》
- XML Enhancement in SQL Server 2005
- VS环境下 Ibatis .Net 连接sqlserver 2005 碰到的问题 Unable to open connection to "Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0".
- Copy a table from one database to another in SQL Server 2005
- How to Alter a Replicated Article in SQL Server 2005
- Synonyms in SQL Server 2005
- Inside Microsoft SQL Server 2005: T-SQL Programming (数据类型|第一章) XML数据类型
- using xml in sql server(转)
- [转]各种分页 in SQL Server 2005, SQL Server 2000, MS Access and MySQL
- How to Implement an Automatic Sliding Window in a Partitioned Table on SQL Server 2005
- Introduction to SQL Server 2005 XML
- Working with tempdb in SQL Server 2005
- SQL Server error "Xml data type is not supported in distributed queries" and workaround for it
- Disaster Recovery: What to do when the SA account password is lost in SQL Server 2005
- [优秀英文技术文章转载]Passing lists to SQL Server 2005 with XML Parameters
- bookmark: partitioned tables in sql server 2005
- Partitioned Tables and Indexes in SQL Server 2005
- Sqlserver in 实现 参数化查询 XML类型解决方案
- SQL语句执行顺序 in SQL Server 2005