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 2000 Forums
 SQL Server Development (2000)
 DTS Question

Author  Topic 

oahu9872
Posting Yak Master

112 Posts

Posted - 2007-01-18 : 14:46:35
Hello,

I have 1,200 text files that I want to import into a database table. I will have 1,200 new text files every month. Obviously I do not want to DTS them into the database one at a time each month. Is there was way to set up a DTS Package that will look within a folder and upload all of them, or does anyone know of another tool that would allow me to merge the text files into one?

Thank you for your help.

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-01-18 : 18:43:19
A simple Windows command line copy will merge them all into one
This will copy file1, file2 and file3 into a new file named file4.

COPY file1+file2+file3 file4
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-01-18 : 19:30:35
type *.* > myfile.txt
will do that.

Better to use bulk insert.
see
http://www.nigelrivett.net/SQLTsql/ImportTextFiles.html

That is good if the files are small or you want to do processing on them.

If they are large and the same format then you should bulk insert directly to the table.
use
http://www.nigelrivett.net/SQLTsql/s_ProcessAllFilesInDir.html
@ProcSp would be the sp to do the bulk insert (or just replace it with the statement

declare @sql varchar(6000)
select @sql = 'bulk insert mytable from ''' + @FilePath + ''' , ''' + @File + ''' with (fieldterminator='','')' --or whatever
exec (@sql)





==========================================
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 -