問題描述
我整個(gè)上午都在用這個(gè)頭撞墻.
I've been banging my head against the wall with this one all morning.
以下 SQL 代碼及其結(jié)果對(duì)我來說毫無意義:
The following SQL code and its' result makes no sense to me:
select CONVERT(INT, CONVERT(BINARY(30),2691485888))
導(dǎo)致:
-1060082528
什么?為什么結(jié)果不等于我原來的整數(shù)?
What? Why doesn't the result equal my original integer?
我的整個(gè)目標(biāo)是將一個(gè)整數(shù)轉(zhuǎn)換為字節(jié)并將這些字節(jié)存儲(chǔ)到數(shù)據(jù)庫(kù)中,但是沒有讓這個(gè)基本示例工作,我被卡住了.誰能解釋一下我做錯(cuò)了什么?
My whole objective is to convert an integer into bytes and store those bytes into the database, but without getting this basic example to work I am stuck. Can anyone explain what I'm doing wrong?
順便說一下,我使用的是 Sql Server 2005 (9.0.4340)
By the way, I am using Sql Server 2005 (9.0.4340)
推薦答案
正如我在之前的評(píng)論中所指出的,2,691,485,888 比 INT 可以容納的要大.
As I noted in my earlier comment, 2,691,485,888 is larger than what an INT can hold.
這會(huì)起作用:
select CONVERT(BIGINT, CONVERT(BINARY(30), CONVERT(BIGINT, 2691485888)))
這篇關(guān)于在 SQL Server 中從整數(shù)轉(zhuǎn)換為二進(jìn)制并返回的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!