Import Multiple CSV or Excel files to Sql Server Express 2008
I have tried a number of examples on the web- but can't get them to work- Looking to either upload a number of .csv or.xls or.xlsm files (I can change format to solution) to a sqlserver table.
If you have a full end to end example that would be appreciated- can't use SSIS as I have express
All help appreciated
Thanks
April 13th, 2011 5:22am
You can try using OPENROWSET.
Please find How to Import Data from EXCEL
here.
You can create Stored Procedure (SP) for importing multiple files and run SP for running all loads together.Please vote for answer if it helps you.
Free Windows Admin Tool Kit Click here and download it now
April 13th, 2011 5:30am
check below link
http://www.mssqltips.com/tutorial.asp?tutorial=211If you think my suggestion is useful, please rate it as helpful. If it has helped you to resolve the problem, please Mark it as Answer. DVR
April 13th, 2011 6:21am
Thanks for your reply- The imports seem to be for know file name- the names of the files coming in aren't known in advance- I just know the naming convention and file type.
I'm looking for a loop routine to import from all the files of a particular format e.g Filename*.xls so import all files beginining with Filename and with .xls at end
Then idealy move the file to an archive folder
this link
http://www.databasejournal.com/features/mssql/article.php/3325701/Import-multiple-Files-to-SQL-Server-using-T-SQL.htm is basicaly what I wanted to do but couldn't get it to work
As mentioned in initial query- I only have sqlserver express so can't create an SSIS package to do it.
Thanks
Free Windows Admin Tool Kit Click here and download it now
April 13th, 2011 11:24am
use
http://plexussql.blogspot.com/2010/04/looping-through-excel-files-and-sheets.html
http://plexussql.blogspot.com/2010/06/looping-through-csv-files-using-ssis.htmlSincerely SH -- MVP, MCITP 2008, MCTS 2008 & 2005 -- Please kindly mark the post(s) that answered your question and/or vote for the post(s).
April 13th, 2011 11:32am
can't use SSIS as I have express
If you can't use SSIS, you're in the wrong
forum! It's very
easy in SSIS.
Please mark the post as answered if it answers your question | My SSIS Blog:
http://microsoft-ssis.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
April 13th, 2011 11:40am
Hi David_1234,
Can you please specify which part from http://www.databasejournal.com/features/mssql/article.php/3325701/Import-multiple-Files-to-SQL-Server-using-T-SQL.htm you could not get to work?
We can concentrate on that part.
I think what you are trying to do can be broken into:
1. Load Excel
2. Move to different folder ( In this you need to use master.dbo.xp_cmdshell )
Also, Do you have same structure for all excel files?Please vote for answer if it helps you.
April 15th, 2011 1:45am
Jerry
Sorry I had left this query behind and had to do a tempory fix on it.- would like to do it correctly now if possible
I created the procedure per the above site using method 1- so created the DB & tables- created the CSV files in same path as suggested- all in same format
In trying either example 1 or 2 I get the same response- see below
In running Xp_CMDshell is there something I should run to enable this or is it on automatically?
Details back when I run query:-
Exec
usp_ImportMultipleFiles
'c:\myimport\',
'*.csv',
'Account'
are
(4 row(s) affected)
(1 row(s) affected)
(3 row(s) affected)
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ','.
(1 row(s) affected)
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ','.
(1 row(s) affected)
Thanks for any help
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ','.
(1 row(s) affected)
(1 row(s) affected)
Free Windows Admin Tool Kit Click here and download it now
May 16th, 2011 8:02am