【发布时间】:2018-03-25 22:07:20
【问题描述】:
我使用 SQL Server 2005。我在表 (ref, column1, column2) 中有三列。第 1 列和第 2 列是浮点数,ref 是 1,column1 是 1000,column2 是 1000。
select *
from table
where ref = 1 and column1 = column2
返回 0 行
我将它们转换为十进制,它们是相同的。
它们看起来相等,但查询返回它们不相等。怎么可能?
编辑:
Here is the screenshot. They are not same. What causes this and how can i fix it?
【问题讨论】:
-
向我们展示几行示例数据,其中一行包含您的示例 1,1000,1000。查看表的 DDL 也会很有帮助。
-
很可能值不一样。运行
SELECT CAST(column1 AS binary(8)) AS column1, CAST(column2 AS binary(8)) AS column2 FROM table WHERE ref = 1;。 -
您可以尝试
... where ref = 1 and Abs( column1 - column2 ) < 0.001将差异与 iota 进行比较。根据值的范围,与值的一小部分进行比较而不是绝对限制可能更有意义,例如Abs( column1 - column2 ) < Abs( column1 * 0.001 ). -
我添加了截图
标签: sql sql-server tsql compare equals