本文介绍了SQL Server 2012 将 CSV 导入到映射列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在尝试将大约 10000 行(从 CSV 文件)导入到现有表中.
I'm currently trying to import about 10000 rows (from a CSV file) into an existing table.
我只有 1 个要导入的列,但在我的表中还有一个名为 TypeId
的列,我需要将其设置为静态值,即 99E05902-1F68-4B1A-BC66-A143BFF19E37
.
I only have 1 column which I'm trying to import, but in my table I have a another column called TypeId
which I need to set to a static value i.e. 99E05902-1F68-4B1A-BC66-A143BFF19E37
.
所以我需要类似的东西
INSERT INTO TABLE ([Name], [TypeId])
Values (@Name (CSV value), "99E05902-1F68-4B1A-BC66-A143BFF19E37")
任何例子都会很棒.
谢谢
推荐答案
如上所说将数据导入到临时表中,然后将值插入到实际表中
As mentioned above import the data into a temporary table and then insert the value into the actual table
DECLARE @TempTable TABLE (Name nvarchar(max))
BULK INSERT @TempTable
FROM ‘C:\YourFilePath\file.csv’
WITH ( FIELDTERMINATOR = ‘,’,
ROWTERMINATOR = ‘\n’
)
INSERT INTO TABLE ([Name], [TypeId])
Select Name,'99E05902-1F68-4B1A-BC66-A143BFF19E37' from @TempTable
这篇关于SQL Server 2012 将 CSV 导入到映射列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!