首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > IBM DB2 >

db2数据库表中不同字段相加的语句有关问题

2012-08-10 
db2数据库表中不同字段相加的语句问题selectcase when BD.Balance BD.NormalBalance then awhen BD.Ov

db2数据库表中不同字段相加的语句问题
select 
case when BD.Balance = BD.NormalBalance then 'a'
when BD.OverDueBalance > 0 then 'e'
when BD.DullBalance > 0 then 'f'
when BD.BadBalance > 0 then 'g'
when BD.Balance+BD.InterestBalance1+BD.InterestBalance2 = 0 then 'o' end as 账户状态
 from BUSINESS_DUEBILL BD where BusinessType in('1110161','1110162')

这条语句中的“BD.Balance+BD.InterestBalance1+BD.InterestBalance2 = 0” 是这样写吗? 但是条件符合的情况不返回o呢????应该怎么写呢????

[解决办法]
检查字段内容是否有NULL
COALESCE(BD.Balance,0) +COALESCE(BD.InterestBalance1,0) +COALESCE(BD.InterestBalance2,0)

热点排行