|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
import multiple text files
i'm using following SP to import 4549 text files from a directory to a SQL Server table (1 column-ntext(16)). i want that 1 text appears in 1 cell of the table, so i use a row/fieldterminator that doesn't exist.
When i execute the SP, the logtable shows that 4549 files are imported, but in my texttable appear only 3850 rows! anyone an idea what goes wrong? -- Exec usp_ImportMultipleFiles 'c:\myimport\', '*.*', 'Account' -- Create procedure usp_ImportMultipleFiles @filepath varchar(500), @pattern varchar(100), @TableName varchar(128) as set quoted_identifier off declare @query varchar(1000) declare @max1 int declare @count1 int Declare @filename varchar(100) set @count1 =0 create table #x (name varchar(200)) set @query ='master.dbo.xp_cmdshell "dir '+@filepath+@pattern +' /b"' insert #x exec (@query) delete from #x where name is NULL select identity(int,1,1) as ID, name into #y from #x drop table #x set @max1 = (select max(ID) from #y) --print @max1 --print @count1 While @count1 <= @max1 begin set @count1=@count1+1 set @filename = (select name from #y where [id] = @count1) set @Query ='BULK INSERT '+ @Tablename + ' FROM "'+ @Filepath+@Filename+'" WITH ( FIELDTERMINATOR = "%%&&%%",ROWTERMINATOR = "%%&&%%")' --print @query exec (@query) insert into logtable (query) select @query end drop table #y |
|
#2
|
|||
|
|||
|
no answer...
is there anyone who has an other stored procedure or who knows an other way to import multiple text files? i'm desperate... ![]() |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > import multiple text files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|