ISNULL函数在SQL Server2005中不起作用 [英] ISNULL function is not working in sql server2005

查看:76
本文介绍了ISNULL函数在SQL Server2005中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表格中,id的整数列

我正在使用Isnull()函数来选择最大ID,例如

 选择 max(isnull(id, 0 ))+ 1 来自  


但这是行不通的.当表为null时,它将显示null值.
我不知道为什么?

请帮助我.

解决方案

  select  isull(max(id) , 0 )+ 1 来自 表格 


在您的代码中,选择max(no records),它(正确)为null.

使用isnull(max(id),0)+1

如果表为空,则max(id)将返回null,而notull将其替换为零.

希望这会有所帮助,

Pablo.


如果表中没有任何记录,则您的查询将不返回任何结果行,因此您不会获得任何最大的值.

一种方法是使用标量.因此,例如这样的内容:

 选择  coalesce ((选择 max(id) from  YourTable), 0 )


In my table has integer column for id

I am using Isnull() function for select maximum id like

select max(isnull(id,0))+1 from table


But it is not working. When the table is null it displays null null value.
I didn''t know Why?

Please help me.

解决方案

select isnull(max(id),0)+1 from table


In your code, you select max(no records), which is (correctly) null.

Use isnull(max(id),0)+1

If the table is empty, max(id) will return null, and isnull will replace it by zero.

Hope this helps,

Pablo.


If the table contans no records, your query will not return any result rows hence you''re not getting any macimum value.

One way to do this is to use a scalar. So for example something like this:

select coalesce( (select max(id) from YourTable), 0)


这篇关于ISNULL函数在SQL Server2005中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆