可能错误 - SQL Server中的错误

时间:2013-11-20 15:04:27

标签: sql sql-server sql-server-2008-r2

当我执行查询时

select  * from Brands  where int1 = 1 and iswebactive=0 and ESHOP_CODE=1

在Sql Server中,服务器返回2行。 当我执行查询

select  * from Brands  where isnull(int1,0) = 1 and iswebactive=0 and ESHOP_CODE=1

Sql server返回超过2行。问题是有650000条记录,其中int1 = 1,但第一个查询只返回2行。 字段类型为:

int1 : int
iswebactive : tinyint
ESHOP_CODE : smallint

为什么会这样?


select  int1,* from Brands  where int1 = 1 and iswebactive=0 and ESHOP_CODE=1 

(返回58行。)

select  int1,* from Brands  where isnull(int1,0) = 1 and iswebactive=0 and ESHOP_CODE=1

(返回16134行)

SQL Server的版本是2008 R2 Express。

我的问题是,当我使用isnull函数(第二个查询)时,结果是正确的!

为什么第一个查询只返回58行?

1 个答案:

答案 0 :(得分:0)

SQL Server中没有这样的Bug,至少对于这些类型的简单选择查询。通过细分和检查查看您的选择查询执行。或者您可能只是尝试使用列值问题

SELECT ISNULL(COL_NAME,0) FROM TABLE_NAME 

为所有列和&看看结果。

相关问题