Who said anything about cursors? CREATE TABLE #files (filename varchar(128))INSERT INTO #files (filename) EXEC master..xp_cmdshell 'dir/b c:\*.txt'DELETE #files WHERE NullIf(filename, 'File Not Found') IS NULLDECLARE @sql varchar(8000)WHILE EXISTS (SELECT * FROM #files) BEGIN SELECT @sql='' SELECT TOP 50 @sql=@sql+'BULK INSERT myTable FROM ''C:\' + filename + ''' WITH (ROWTERMINATOR=''\n'', FIELDTERMINATOR='',''); ' FROM #files DELETE #files WHERE CharIndex(filename, @sql)>0 EXEC(@sql) ENDDROP TABLE #files
Obviously you'd need to change the path for the dir and BULK INSERT calls to point to the actual path of the *.txt files, and change any additional BULK INSERT parameters. And this won't work correctly if you need to BULK INSERT into more than one table, or if the text files have different formats.Wow, did I screw up that example! Maybe it'll work correctly now. Edited by - robvolk on 03/13/2003 11:48:01