您是否嘗試過用一個簡單的BULK INSERT
,上傳數據到一個臨時表中首先使用BULK INSERT像到SQL Server ....
創建臨時表
CREATE TABLE UploadFile_Staging
(accountno INT
, companyname VARCHAR (100)
, address1 VARCHAR(100)
)
GO
散裝插入
BULK INSERT UploadFile_Staging
FROM N'D:\File_Folder\Data.txt'
WITH (FIRSTROW = 2
,FIELDTERMINATOR = '|'
,ROWTERMINATOR = '\n'
)
GO
一旦你有數據在sql server表中使用下面的更新語句來擺脫文本限定符的雙引號和轉義字符。
數據整潔查詢
UPDATE UploadFile_Staging
SET companyname = REPLACE(LEFT(STUFF(companyname,1,1,'') , LEN(companyname)- 2) , '\"', '"')
,address1 = REPLACE(LEFT(STUFF(address1,1,1,'') , LEN(address1)- 2) , '\"', '"')
結果集
╔═══════════╦═════════════╦══════════════╗
║ accountno ║ companyname ║ address1 ║
╠═══════════╬═════════════╬══════════════╣
║ 1234 ║ Toys "R" Us ║ 123 Main St. ║
╚═══════════╩═════════════╩══════════════╝