在 SQL Server 中从整数转换为二进制并返回
- 作者: 茅山灵媒
- 来源: 51数据库
- 2022-12-06
问题描述
我整个上午都在用这个头撞墙.
I've been banging my head against the wall with this one all morning.
以下 SQL 代码及其结果对我来说毫无意义:
The following SQL code and its' result makes no sense to me:
select CONVERT(INT, CONVERT(BINARY(30),2691485888))
导致:
-1060082528
什么?为什么结果不等于我原来的整数?
What? Why doesn't the result equal my original integer?
我的整个目标是将一个整数转换为字节并将这些字节存储到数据库中,但是没有让这个基本示例工作,我被卡住了.谁能解释一下我做错了什么?
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)
推荐答案
正如我在之前的评论中所指出的,2,691,485,888 比 INT 可以容纳的要大.
As I noted in my earlier comment, 2,691,485,888 is larger than what an INT can hold.
这会起作用:
select CONVERT(BIGINT, CONVERT(BINARY(30), CONVERT(BIGINT, 2691485888)))
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0
