|
|
|
Forum 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.
CREATE TABLE XmlImportTest ( xmlFileName VARCHAR(300), xml_data xml ) GO
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 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
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Yesterday @ 6:54 PM
Points: 721,
Visits: 1,375
|
|
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:
http://msdn.microsoft.com/en-us/library/ms178129(SQL.90).aspx
|
|
|
|