Over a million developers have joined DZone.

XML File To SQL

·
// XML file to SQL


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 
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}