create table #t(fname varchar(260),depth int,isf bit)
insert into #t exec master..xp_dirtree 'c:\log文件夹',1,1
declare tb cursor for select fn='c:\log文件夹\'+fname from #t
where isf=1 and fname like '%.txt' --取.txt(文本文件)
DECLARE @fieldTerminator1 AS VARCHAR(10),@ROWTERMINATOR1 AS VARCHAR(20)
SELECT @fieldTerminator1=';', @ROWTERMINATOR1='\n'
declare @fn varchar(8000)
open tb
fetch next from tb into @fn
while @@fetch_status=0
begin
--下面是查询语句,需要根据你的情况改为插入语句
exec ('BULK INSERT 表 FROM '''+@fn+''' WITH ( FIELDTERMINATOR ='''+@fieldTerminator1+''', ROWTERMINATOR = '''+@ROWTERMINATOR1+''')')
fetch next from tb into @fn
end
close tb
deallocate tb
drop table #t