Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SSIS and Import/Export (2005)
 Import Multiple CSV from folder into sql

Author  Topic 

rwaldron
Posting Yak Master

131 Posts

Posted - 2009-06-09 : 08:12:02
Hi all,
I am looking for the best way to import multiple csv files from a folder into sql..
The plan is to firstly rename these files from say csv to wrk.
Then import these wrk files into an existing table in sql.
Then delete wrk files..
Then run the process again for any new cav files..Can someone help me..

I have used Bulk insert to insert file1.csv but I need to be able to use wildcard (any CSV Files)



eg:

BULK INSERT OrdersBulk
FROM 'c:\file.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-09 : 13:26:00
you can use ssis component for each loop to look for all files in a particular location and transfer it to sql table. see below

http://www.sqlis.com/post/Looping-over-files-with-the-Foreach-Loop.aspx
Go to Top of Page

kishore_pen
Starting Member

49 Posts

Posted - 2009-06-16 : 07:36:01
try bcp command.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2009-06-16 : 08:17:15
see
http://www.nigelrivett.net/SQLTsql/ImportTextFiles.html

It caters for importing to different tables and formats. If you just want to import to a single table you can get rid of the second sp and change the bulk insert to import to your table.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -