如何在派生列转换中替换双引号?

发布于 2024-11-12 03:09:46 字数 314 浏览 0 评论 0原文

我有平面文件。我正在使用 ssis 将数据从平面文件加载到源表。其中一列具有以下值:

<Somecol1 =""1"" col1values= ""223,567,890,653"">

我想要以下列输出:

<Somecol1 ="1" col1values= "223,567,890,653">

我尝试在派生列中替换。

REPLACE( COLA, "\"","\")

但这不起作用。

I have flat file. I am loading data from flat file to source table using ssis.And one of the column has following values:

<Somecol1 =""1"" col1values= ""223,567,890,653"">

I want following column output:

<Somecol1 ="1" col1values= "223,567,890,653">

I have tried to replace in derived column.

REPLACE( COLA, "\"","\")

but this doesnt work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柳絮泡泡 2024-11-19 03:09:46

我认为除了替换字符串中的附加斜杠之外,您几乎已经得到了正确的表达式。以下是可能适合您的表达方式。

表达式#1:删除给定字符串中的所有双引号。

REPLACE(COLA, "\"", "")

表达式 #2: 将所有出现的双引号替换为出现的双引号。

REPLACE(COLA, "\"\"", "\"")

以下是演示表达式 #1 的示例:

  1. 屏幕截图 #1 显示包将读取的 CSV 文件。
  2. 屏幕截图 #2 显示数据流任务内的派生列转换,该转换将替换名为 Header 的第一列中的所有双引号
  3. 屏幕截图#3 显示了包执行后表中的数据。请注意,第二列中的双引号保持原样,因为没有表达式可以替换它们。

下面是演示表达式#2 的示例:

  1. 此示例将使用与示例 1 中相同的文件。请参阅屏幕截图#1
  2. 屏幕截图 #4 显示数据流任务内的派生列转换,该转换将替换所有出现的双引号在名为 标题 的第一列中出现双引号。
  3. 屏幕截图 #5 显示包执行后表中的数据。请注意,第二列中的双引号保持原样,因为没有表达式可以替换它们。

希望有帮助。

屏幕截图 #1:

1

屏幕截图 #2:

2

屏幕截图#3:

3

屏幕截图 #4:

4

屏幕截图 #5 :

5

I think you have almost got the expression correct except for the additional slash in the replacement string. Here are the expressions that might work for you.

Expression #1: Removes all double quotes within a given string.

REPLACE(COLA, "\"", "")

Expression #2: Replaces all double occurrences of double quotes with single occurrence of double quotes.

REPLACE(COLA, "\"\"", "\"")

Here is an example that demonstrates expression #1:

  1. Screenshot #1 shows the CSV file that will be read by a package.
  2. Screenshot #2 shows the Derived Column transformation inside the Data Flow task that will replace all double quotes within the first column named as Header.
  3. Screenshot #3 shows data in the table after the package execution. Notice that the double quotes in second column are left as it is because there is no expression to replace them.

Here is an example that demonstrates expression #2:

  1. This example will use the same file as in example 1. Refer screenshot #1.
  2. Screenshot #4 shows the Derived Column transformation inside the Data Flow task that will replace all double occurrences of double quotes with single occurrence of double quotes within the first column named as Header.
  3. Screenshot #5 shows data in the table after the package execution. Notice that the double quotes in second column are left as it is because there is no expression to replace them.

Hope that helps.

Screenshot #1:

1

Screenshot #2:

2

Screenshot #3:

3

Screenshot #4:

4

Screenshot #5:

5

悟红尘 2024-11-19 03:09:46

如果您的其他列没有同样的问题,这可能不起作用,但如果这是您要导入的唯一文本列或者它们都是这样,您可以将文本标识符更改为两个双引号而不是一个。然后,SSIS 会正确地将其从平面文件中取出,您无需稍后尝试清理它。

This may not work if your other columns don't have this same issue, but if this is the only text column you are importing or they are all like this, you could change your text identifier to be two double quotes instead of one. Then SSIS would bring it out of the flat file correctly and you wouldn't have to deal with trying to clean it up later.

情话墙 2024-11-19 03:09:46

请查找以下示例

REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(Client_1,"\"",""),"*",""),",",""),"[",""),"]",""),"'",""),"!",""),"/",""),"<>","")

Please find below samples

REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(Client_1,"\"",""),"*",""),",",""),"[",""),"]",""),"'",""),"!",""),"/",""),"<>","")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文