OPENROWSET now supports the BULK keyword which lets us import XML files with ease.
A little example:
CREATE TABLE XmlImportTest ( xmlFileName VARCHAR(300), xml_data xml ) GO DECLARE @xmlFileName VARCHAR(300) SELECT @xmlFileName = 'c:\TestXml.xml'
-- dynamic sql is just so we can use @xmlFileName variable in OPENROWSET EXEC(' INSERT INTO XmlImportTest(xmlFileName, xml_data) SELECT ''' + @xmlFileName + ''', xmlData FROM ( SELECT * FROM OPENROWSET (BULK ''' + @xmlFileName + ''' , SINGLE_BLOB) AS XMLDATA ) AS FileImport (XMLDATA) ') GO SELECT * FROM XmlImportTest DROP TABLE XmlImportTest
SINGLE_BLOB is recommended when importing XML files because only it supports all Windows encoding conversions.
http://weblogs.sqlteam.com/mladenp/archive/2007/06/18/60235.aspx
No comments:
Post a Comment