简体   繁体   English

SSIS:使用特殊字符导出和导入CSV文件

[英]SSIS: Export and import CSV file with special characters

I have to export a CSV file from a database using SSIS. 我必须使用SSIS从数据库导出CSV文件。
It's very easy to do that, but the problems come when I have to import the same CSV file into another database (from another server) because I have 2 columns which contains characters like: comma (,), apostrophe ('), semicolon (;), colon (:), vertical bar (|). 这样做非常容易,但是当我必须将同一CSV文件(从另一台服务器)导入到另一个数据库时,问题就来了,因为我有2列,其中包含以下字符:逗号(,),撇号('),分号( ;),冒号(:),竖线(|)。 I don't know which should be the settings for the Flat File Connection, which should be the header row delimiter, row delimiter, column delimiter...in order to to the both actions (export and then import). 我不知道应该是平面文件连接的设置,应该是标题行定界符,行定界符,列定界符...以便同时执行这两个操作(导出然后导入)。

I tried many combinations but I still get errors like: 我尝试了多种组合,但仍然出现类似以下错误:

[Flat File Source [2]] Error: Data conversion failed. [平面文件源[2]]错误:数据转换失败。 The data conversion for column "ActiveJobs" returned status value 2 and status text "The value could not be converted because of a potential loss of data.". 列“ ActiveJobs”的数据转换返回状态值2和状态文本“由于潜在的数据丢失而无法转换该值”。 The data is mixing there because of the characters and spaces. 由于字符和空格,数据混合在那里。

In SSIS you have the option of specifying a text delimiter\\qualifier for flat text files. 在SSIS中,可以选择为平面文本文件指定文本定界符\\限定符。 You could use this to export columns that have special characters. 您可以使用它导出具有特殊字符的列。 For example if your row looks like: 例如,如果您的行如下所示:

column1value co,lumn2value co;lumn3value

then the exported row using ' , ' as the column delimiter and ' " ' as the text delimiter would look like "column1value","co,lumn2value","co;lumn3value" 然后使用“”作为列分隔符和““”作为文本分隔符会是什么样的出口排"column1value","co,lumn2value","co;lumn3value"

I don't remember what happens if you have a value like co"lumn4value or "column4value" 我不记得如果您使用co"lumn4value or "column4value"这样的值会发生什么

but I think that you can use as a delimiter any character as text delimiter if you have issues with double quotes. 但是我认为如果双引号有问题,您可以将任何字符用作文本定界符。 for example '•' (alt + 0149) 例如“•”(alt + 0149)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM