【问题标题】:Inserting id that is varchar into uniqueidentifier将 varchar 的 id 插入 uniqueidentifier
【发布时间】:2012-09-08 17:09:28
【问题描述】:

我正在尝试将数据从一个表插入到另一个表。源表包含一个 GUID,它现在是一个文本字段。我想将它插入到 Uniqueidentifier 字段中。这是查询和错误。

insert into Tag 
(
    BusinessId, 
    AdImage, 
    AdSize, 
    DayCycleId, 
    CreatedOn, 
    IsActive, 
    Name, 
    CreatedBy
)
select cast(ID as uniqueidentifier), 
    [IMAGE], 
    '1', 
    cast('71479D27-D7A2-4439-99CB-0B536DCEFB45' as uniqueidentifier), 
    GETDATE(), 
    1, 
    'NA', 
    cast('49493D4F-A0B0-43A5-8B32-45572E4D7E43' as uniqueidentifier) 
from IMPORT

错误:

消息 8169,第 16 级,状态 2,第 1 行

从字符串转换为唯一标识符时转换失败。

【问题讨论】:

  • SQL Server?哪个版本? IMPORT.ID究竟有什么格式?
  • SQL Server 2008。IMPORT.ID 是 nvarchar(32)。
  • 您知道 GUID 需要 36 个字符,而不仅仅是 32 个字符,因为破折号?我想您的 GUID 已被截断,因此无法转换回有效的 GUID。

标签: sql sql-server-2008 insert guid uniqueidentifier


【解决方案1】:

将您的属性 ID 类型更改为 nvarchar(36)

nvarchar(32) 或

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-09
    • 2010-11-26
    • 2010-10-15
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多