Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

sp_xml_PrepareDocumentFromColumn

By Simon Sabin,

Do you want to use OPENXML with an xml document in a table, this procdure will do it for you.
Pass in the SQL that will return the column of data, it will return the document handle which can then be used with OPENXML.

Example

DROP TABLE Tab

CREATE TABLE Tab (doc ntext)

INSERT INTO Tab VALUES (''
+ REPLICATE('' + char(10), 50)
+ REPLICATE('' + char(10), 50)
+ REPLICATE('' + char(10), 50)
+ REPLICATE('' + char(10), 50)
+ REPLICATE('' + char(10), 50)
+ REPLICATE('' + char(10), 50)
+ '')
SELECT DATALENGTH (Doc) FROM TAb
DECLARE @iDoc int
exec sp_xml_PrepareDocumentFromColumn @iDoc OUTPUT, 'SELECT TOP 1 doc FROM Tab'
SELECT * FROM OPENXML (@iDoc ,'//customers')
WITH (id varchar(10))
exec sp_xml_removedocument @iDoc
GO

Total article views: 492 | Views in the last 30 days: 2
 
Related Articles
FORUM
FORUM

OPENXML

Retreiving data from OPENXML

FORUM

Updating DB using OPENXML

How to update only columns selected using OPENXML

FORUM

Dynamic SQL for variable TableName with OpenXML

Using OpenXML within Dynamic SQL

ARTICLE

Using OpenXML

SQL Server 2000 added XML support awhile back, though it was limited in what is offered and can be a...

Tags
miscellaneous    
t-sql    
 
Contribute