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 ««12345»»»

Import Excel Spreadsheet to Database Tables Expand / Collapse
Author
Message
Posted Wednesday, February 17, 2010 6:20 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, February 04, 2011 7:20 AM
Points: 977, Visits: 1,499
Great article!

Really good info from Jim Cheong too!

I know I'll be upgrading some old Excel work sooner rather than later, and the current lack of a 64 bit Jet driver has had me wondering what best to do.

Thanks!


Tom Garth
Vertical Solutions

"There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers
Post #866954
Posted Wednesday, February 17, 2010 6:21 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, January 20, 2014 9:25 AM
Points: 14, Visits: 48
Cannot download your stored procedure - link is broken?
Post #866958
Posted Wednesday, February 17, 2010 6:26 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, January 02, 2014 9:51 AM
Points: 531, Visits: 429
The link in the article does not work anymore. Please use the links in the "Resources" in the end of the article.


Post #866969
Posted Wednesday, February 17, 2010 7:23 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, December 21, 2012 6:34 AM
Points: 20, Visits: 129
I tried your code on a WinXP 64-bit workstation connected to SQL Server 2008 64-bit. I always get this error:

Cannot bulk load. The file "C:\TestBook.xml" does not exist. at line 1
Msg 50000, Level 16, State 1, Procedure uspImportExcelSheet, Line 497
Cannot bulk load. The file "C:\TestBook.xml" does not exist.

No matter where I put the "TestBook.xml" file ("C:" or a network drive), it cannot find the file.
Am I missing something?



Denis W. Repke
Post #867032
Posted Wednesday, February 17, 2010 7:42 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, February 17, 2010 11:38 AM
Points: 2, Visits: 8
When running this script, I get:

SET @WorkSheet=NULL; SELECT @WorkSheet=CAST(BulkColumn as xml) FROM OPENROWSET (BULK 'M:\HTS\Export\currency.xls', SINGLE_BLOB ) A;
XML parsing: line 0, character 0, unrecognized input signature at line 1
Msg 50000, Level 16, State 1, Procedure uspImportExcelSheet, Line 497
XML parsing: line 0, character 0, unrecognized input signature

Tried a few xls files, all gave the same error.
Post #867083
Posted Wednesday, February 17, 2010 8:21 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, August 14, 2013 9:27 AM
Points: 266, Visits: 161
This may be a little off-topic, but is there a way to convert dBase files to xml for import into SQL Server 2008 (64-bit) tables?
Post #867135
Posted Wednesday, February 17, 2010 9:06 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, December 17, 2012 10:05 PM
Points: 4, Visits: 11,712
Here is the Openrowset/Opendatasource Test Script you can use after the above installation.

/*
Ref: http://www.connectionstrings.com/excel-2007
If you want to read the column headers into the result set (using HDR=NO even though
there is a header) and the column data is numeric, use IMEX=1 to avoid crash.

To always use IMEX=1 is a safer way to retrieve data for mixed data columns. Consider
the scenario that one Excel file might work fine cause that file's data causes the
driver to guess one data type while another file, containing other data, causes the
driver to guess another data type. This can cause your app to crash.
*/

SELECT *
FROM OPENROWSET(
'Microsoft.ACE.OLEDB.12.0',
'Excel 12.0 XML;HDR=YES;IMEX=1Database=c:\install\AgeHeartRate.xls;',
'SELECT * FROM [Sheet1$]');

Select * from opendatasource(
'Microsoft.ACE.OLEDB.12.0',
'Excel 12.0 Xml;IMEX=1;Database=c:\install\AgeHeartRate.xls;')...[Sheet1$]
Post #867180
Posted Wednesday, February 17, 2010 9:56 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, January 02, 2014 9:51 AM
Points: 531, Visits: 429
Denis,

First, in Your scenario, the file needs to be in the C:\ drive of the SQL Server box;

Second, check the file security:
If you log on SQL Server by a SQL Server login, the SQL Server service (process) account is used to access the file.

If you log on SQL Server by Windows Authentication, you can read only those files that can be accessed by your windows account, regardless of the security settings of the SQL Server service account.




Post #867229
Posted Wednesday, February 17, 2010 9:57 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, January 02, 2014 9:51 AM
Points: 531, Visits: 429
sckemp1,

Did you save your spreadsheet as xml in Excel?



Post #867230
Posted Wednesday, February 17, 2010 9:57 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, January 20, 2014 9:25 AM
Points: 14, Visits: 48
Gordon,

what program creates your dBase files?

Newer version of dBase, and their clones such as Visual Foxpro, have support for converting tables to XML files.
Otherwise it is quite elementary, although not so fast, to skip through the table and adding XML tags around the values.
Post #867231
« Prev Topic | Next Topic »

Add to briefcase ««12345»»»

Permissions Expand / Collapse