日期:2014-05-17 浏览次数:21062 次
CREATE PROCEDURE [dbo].[ImportFile]
@FilePath NVARCHAR(200), --eg:'D:\\DATAExchange\\CSVTMP'
@FileName NVARCHAR(100), --eg:'ExportFileOne.csv'
@TableName NVARCHAR(100) --eg: 'MSSQLExportFileTableOne'
AS
BEGIN
DECLARE @DelSQLstr NVARCHAR(600)
DECLARE @ImpSQLstr NVARCHAR(600)
-- Clear the Content of the Destination Table
--SET @DelSQLstr='DELETE FROM ' +@TableName
--Exec sp_executesql @DelSQLstr
-- Import csv Data Into the Destination Table
SET @ImpSQLstr='INSERT INTO ' + @TableName +
' SELECT * FROM OPENROWSET(''MSDASQL'', '' Driver={Microsoft Text Driver (*.txt; *.csv)};
DEFAULTDIR='+@FilePath+'; Extensions=CSV;'',''SELECT * FROM "'+@FileName+'" '')'
Exec sp_executesql @ImpSQLstr
SELECT @@ROWCOUNT
END