我整个上午都在用这个头撞墙.
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)))
这篇关于在 SQL Server 中从整数转换为二进制并返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
将每个子标记转换为具有多个分隔符的单列-SQLConverting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(将每个子标记转换为具有多个分隔符的单列-SQ
如何从多个表创建视图?How can I create a view from more than one table?(如何从多个表创建视图?)
根据前一行内的计算值创建计算值Create calculated value based on calculated value inside previous row(根据前一行内的计算值创建计算值)
如何将表格的前两列堆叠成一列,但也仅将第三How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何将表格的前两列堆
递归 t-sql 查询Recursive t-sql query(递归 t-sql 查询)
将月份名称转换为日期/月份编号(问题和答案的组Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(将月份名称转换为日期/月份编号(问题和答案的组合