2012-04-11 51 views
1

我有逗號分隔的值。我需要一個查詢插入到SQL Server 2008中具有不同的行SQL Server 2008中以逗號分隔的值

貝德福德,布盧姆菲爾德,寬廣的頂上,Colerain,坎伯蘭山谷,東普羅維登斯,東聖克萊爾,哈里森,合,傑尼阿塔,金梅爾,國王, 倫敦德里,曼恩,門羅,納皮爾,蛇泉, 南安普敦,南伍德伯裏,聯合,西普羅維登斯,西聖克萊爾, 伍德伯裏,貝德福德,Coaldale,埃弗裏特,合和,Hyndman,Manns Choice, 新巴黎,Pleasantville,Rainsburg,St. Clairsville,Saxton, Schellsburg,Woodbury,

+0

在文本文件中並將其存儲在表中 – 2012-04-11 06:59:03

回答

1

一種方法:

-- create a table to load the city names into 
CREATE TABLE CitiesBulkLoad (CityName VARCHAR(100)) 

-- load the file into that staging table 
BULK INSERT CitiesBulkLoad 
FROM 'd:\commacities.txt' -- replace with **YOUR** file name here!! 
WITH 
(
    FIELDTERMINATOR = ',', 
    ROWTERMINATOR = ',' 
) 
GO 

-- now you should have the entries in that staging table 
SELECT * FROM CitiesBulkLoad