相关疑难解决方法(0)

在SQL Server中将varchar转换为uniqueidentifier

我无法控制模式的表,包含一个定义为varchar(50)的列,它以'a89b1acd95016ae6b9c8aabb07da2010'格式存储uniqueidentifiers(无连字符)

我想将这些转换为SQL中的uniqueidentifier,以便传递给.Net Guid.但是,以下查询行不适合我:

select cast('a89b1acd95016ae6b9c8aabb07da2010' as uniqueidentifier)
select convert(uniqueidentifier, 'a89b1acd95016ae6b9c8aabb07da2010')
Run Code Online (Sandbox Code Playgroud)

并导致:

Msg 8169, Level 16, State 2, Line 1
Conversion failed when converting from a character string to uniqueidentifier.

使用带连字符的uniqueidentifier的相同查询工作正常,但数据不以该格式存储.

是否有另一种(有效的)方法将这些字符串转换为SQL中的uniqueidentifier. - 我不想在.Net代码中这样做.

sql sql-server-2005 uniqueidentifier

97
推荐指数
4
解决办法
23万
查看次数

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

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

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

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

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

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

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

没有花括号或引号.

excel ssis data-conversion sql-server-2012

7
推荐指数
1
解决办法
2万
查看次数