Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

XML File Load via OpenRowSet Expand / Collapse
Posted Thursday, August 16, 2012 3:40 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, August 20, 2012 11:55 AM
Points: 3, Visits: 10
I am using the following code to import an XML file via Sql Server. The XML file is verified to be properly formatted. If I import the entire file the results of the final SQL statement are empty. If I remove half the data in the file it imports fine. I have switched the top and the bottom half of data to rule out a character set issue. It seems to be a size issue? Has anyone had this problem? I can import the file with no issue via SSIS but I would rather use this method. Any help would be greatly appreciated.

xmlFileName VARCHAR(300),
xml_data xml

DECLARE @xmlFileName VARCHAR(300)
SELECT @xmlFileName = '\\servername\e$\xml_test\PD_852_387401.xml'
-- dynamic sql is just so we can use @xmlFileName variable in OPENROWSET
INSERT INTO XmlImportTest(xmlFileName, xml_data)

SELECT ''' + @xmlFileName + ''', xmlData
) AS FileImport (XMLDATA)
SELECT * FROM XmlImportTest

DROP TABLE XmlImportTest

  Post Attachments 
XML.gif (6 views, 36.80 KB)
Post #1346278
Posted Monday, August 20, 2012 9:17 AM

Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, October 28, 2014 12:50 PM
Points: 1,061, Visits: 2,580
IIRC, the SINGLE_BLOB option returns the data as single-row, single-column value of type varbinary(max), and when using OPENROWSET to import LOB data that exceeds 8,000 bytes in length, you have to use a format file to specify the maximum length of the data. See here for more:

Jason Wolfkill
Blog: SQLSouth
Twitter: @SQLSouth
Post #1347274
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse