sql case when

lbph1 2008-08-22 11:40:28
select case sum(f_amount) when null then 0 else sum(f_amount) end as f_amount1 from cc_SaleQuoteFee where FID = 4560
为什么结果还是null,而不是0?????
...全文
1961 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
select sum(isnull(f_amount,0)) as f_amount1 from cc_SaleQuoteFee where FID = 4560

空值的判断使用is null或者is not null
ysai 2008-08-22
  • 打赏
  • 举报
回复
case x when null 就是判断 x = null 成立与否
可sql的定义为:任何值与null比较,得出的结果都是null
所以,when null没有任何意义

null值只能用以下方式处理
x is null
isnull(x, 默认值)
g_lbz 2008-08-22
  • 打赏
  • 举报
回复

select case when sum(f_amount) is null then 0 else sum(f_amount) end as f_amount1
from cc_SaleQuoteFee
where FID = 4560

-狙击手- 2008-08-22
  • 打赏
  • 举报
回复
select sum(isnull(f_amount,0)) as f_amount1
from cc_SaleQuoteFee
where FID = 4560
lgxyz 2008-08-22
  • 打赏
  • 举报
回复
select  sum(isnull(f_amount,0)) as f_amount1 from cc_SaleQuoteFee where FID = 4560 
水族杰纶 2008-08-22
  • 打赏
  • 举报
回复
select case sum(f_amount) when null then 0 else isnull(sum(f_amount),0) end as f_amount1 from cc_SaleQuoteFee where FID = 4560

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧