1

我有一个 csv 文件(管道分隔)。我想删除该 CSV 的第一行,同时,我必须将具有相同文件名的相同文件移动到另一个文件夹中。之后,我必须将该 CSV 插入 SQL 表。我知道,我必须为此使用“批量插入”。但是,我面临的主要困难是移动具有相同文件名的文件(如上所述)。

之后,这个过程将每天继续。所以,我要注意,我将要插入表中的文件必须是新鲜的(我必须拿起最新的文件)。所以,可以有人在这两种情况下帮助我吗?

技术:我使用的是 SQL 和 xp_cmdshell。

Exec sp_configure 'xp_cmdshell',1
reconfigure
exec xp_cmdshell 'robocopy *.txt C:\Users\ngavhane\Desktop\abc C:\Users\ngavhane\Desktop\pqr /XF *att*.txt'
exec xp_cmdshell 'copy C:\Users\ngavhane\Desktop\abc C:\Users\ngavhane\Desktop\ProcessedData'
exec xp_cmdshell 'del C:\Users\ngavhane\Desktop\abc\*.txt'


exec xp_cmdshell 'more +1 C:\Users\ngavhane\Desktop\pqr\*.txt>C:\Users\ngavhane\Desktop\To_be_processed\*.txt'




bulk insert test_21012019
from 'C:\Users\ngavhane\Desktop\To_be_processed\'
with
(

fieldterminator='|',
rowterminator='\n'
);
Print 'File data has been inserted into table' ```
4

0 回答 0