日期:2014-05-17 浏览次数:20539 次
--只做参考用,个人不建议直接用sql来做
--用xp_cmdshell 获取指定路径下面的所有txt 文件名字放入到临时表
--然后定义一个游标逐个处理即可
CREATE TABLE #file (filepath NVARCHAR(200))
INSERT INTO #file EXEC master..xp_cmdshell N'dir /b \\d:\txt\*.txt'
DECLARE @filepath VARCHAR(100),@sql VARCHAR(8000)
DECLARE bcp_cursor CURSOR
FOR
SELECT N'\\d:\txt\' + filepath + '.txt' AS filepath
FROM #file
WHERE filepath IS NOT NULL
OPEN bcp_cursor
FETCH NEXT FROM bcp_cursor INTO @filepath;
WHILE @@FETCH_STATUS = 0
BEGIN
SET @sql = 'bcp xx.dbo.xx in ' + @filepath + ' -c -T'
EXEC master..xp_cmdshell @FullName
FETCH NEXT FROM bcp_cursor INTO @filepath;
END
CLOSE bcp_cursor;
DEALLOCATE bcp_cursor;
----这样?
declare @sTime varchar(12) --start
declare @eTime varchar(12) --end
declare @FileName varchar(100) --
declare @FullName varchar(100)
while @sTime <=@eTime
begin
set @FileName='d:\'+@sTime
set @FullName='bcp xx.dbo.xx in '+@FileName+'.txt -c -T'
EXEC master..xp_cmdshell @FullName
print @FileName+' bcp success...'
set @sTime=@sTime+1 --递增规律??
end