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.
| 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 oneThis will copy file1, file2 and file3 into a new file named file4.COPY file1+file2+file3 file4 |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-01-18 : 19:30:35
|
| type *.* > myfile.txtwill do that.Better to use bulk insert.seehttp://www.nigelrivett.net/SQLTsql/ImportTextFiles.htmlThat 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.usehttp://www.nigelrivett.net/SQLTsql/s_ProcessAllFilesInDir.html@ProcSp would be the sp to do the bulk insert (or just replace it with the statementdeclare @sql varchar(6000)select @sql = 'bulk insert mytable from ''' + @FilePath + ''' , ''' + @File + ''' with (fieldterminator='','')' --or whateverexec (@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. |
 |
|
|
|
|
|