SSIS导入和保存数据时将字符串转换为guid

时间:2021-03-03 15:41:17

I was trying to convert a unicode string from an Excel File into a uniqueidentifier. There are already answers online that seem pretty straight forward:

我试图将一个unicode字符串从Excel文件转换为uniqueidentifier。网上已有答案看起来非常简单:

I've seen this post: Data Conversion Issue in SSIS package - Text to GUID

我看过这篇文章:SSIS包中的数据转换问题 - 文本到GUID

and this post: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/6ce5b4d2-913a-40f1-9797-105783181f5e/ssis-variable-that-should-contain-uniqueidentifier

这篇文章:http://social.msdn.microsoft.com/Forums/sqlserver/en-US/6ce5b4d2-913a-40f1-9797-105783181f5e/ssis-variable-that-should-contain-uniqueidentifier

But this didn't work in SSIS 2012 in Visual Studio 2012 when importing data to SQL Server 2012, I would get the typical conversion error when running it.

但是在将数据导入SQL Server 2012时,这在Visual Studio 2012中的SSIS 2012中不起作用,运行时会出现典型的转换错误。

In the Excel File the Guid (as a string) was stored in this format:

在Excel文件中,Guid(作为字符串)以这种格式存储:

00bce79b-6c7b-427f-9711-17c19475f6e4

00bce79b-6c7b-427F-9711-17c19475f6e4

No curly braces or quotes.

没有花括号或引号。

1 个解决方案

#1


17  

To get this to work, still type in the derived column expression as:

要使其工作,仍然在派生列表达式中键入:

(DT_GUID)("{" + [ColumnName] + "}")

But you need to configure the error output and change the columns where you are doing this conversion to Ignore Failure instead of Fail Component.

但是您需要配置错误输出并将执行此转换的列更改为忽略失败而不是失败组件。

If you do this and run it, it WILL work and properly convert and import despite what the debugger tells you.

如果你这样做并运行它,它将工作并正确转换和导入,尽管调试器告诉你。

#1


17  

To get this to work, still type in the derived column expression as:

要使其工作,仍然在派生列表达式中键入:

(DT_GUID)("{" + [ColumnName] + "}")

But you need to configure the error output and change the columns where you are doing this conversion to Ignore Failure instead of Fail Component.

但是您需要配置错误输出并将执行此转换的列更改为忽略失败而不是失败组件。

If you do this and run it, it WILL work and properly convert and import despite what the debugger tells you.

如果你这样做并运行它,它将工作并正确转换和导入,尽管调试器告诉你。