代码之家  ›  专栏  ›  技术社区  ›  m.edmondson

SQL Server十六进制处理

  •  0
  • m.edmondson  · 技术社区  · 14 年前

    我认为我对SQL Server 2000处理十六进制数的方式有问题。

    如果我做了

    select * from table where [timestamp] = 44731446
    

    它返回的行将时间戳显示为0x0000002AA8C36

    在另一张桌子上,如果我

    select * from table2 where [timestamp] = 44731446
    

    它返回的行将时间戳显示为0x000000002AA8C36(注意缺少2)

    MS Calc告诉我,第一个时间戳=8634666038(十进制),第二个时间戳=44731446(十进制),与我对两个表的原始查询相匹配。

    那么,为什么SQL Server返回了一个不同的数字,却成功地查询了它呢?我相信这是我遇到的更新问题的路径,行不会更新。

    1 回复  |  直到 14 年前
        1
  •  2
  •   Pondlife    14 年前

    select cast(0x0000000202AA8C36 as int)
    

    create table dbo.t (tstamp binary(8) not null)
    go
    
    insert into dbo.t values (0x0000000202AA8C36)
    insert into dbo.t values (0x0000000002AA8C36)
    go
    
    -- returns 2 rows
    select * from dbo.t where tstamp = 44731446
    -- returns 1 row
    select * from dbo.t where tstamp = cast(44731446 as bigint)
    go
    
    drop table dbo.t 
    go