mysql中的IfNull函数似乎对我不起作用

时间:2010-02-19 11:57:30

标签: mysql ifnull

mysql中的IfNull函数似乎对我不起作用....当我执行此查询时

select t1.dAccHeader_id,t1.dAccHeaderName,t1.dAccHeaderAcronym,
t2.dDesignationName as incharge1,
t3.dDesignationName as incharge2,t4.dDesignationName as incharge3
from tbl_accountheader as t1
inner join tbl_designation_master as t2 on t2.dDesignation_id = t1.dPaymentIncharge_1
inner join tbl_designation_master as t3 on t3.dDesignation_id = ifnull(t1.dPaymentIncharge_2,'0')
inner join tbl_designation_master as t4 on t4.dDesignation_id = ifnull(t1.dPaymentIncharge_3,'0')
and t1.dCollege_id='1'
and t1.dIsDelete='0'

这是我的表,

My Table http://www.freeimagehosting.net/uploads/cf77e5a156.jpg

任何sugesstion ......

1 个答案:

答案 0 :(得分:0)

您可以尝试使用coalesce功能

inner join tbl_designation_master as t3 
      on t3.dDesignation_id = coalesce(t1.dPaymentIncharge_2,'0')

如果您的ID是一个数字,您也可以删除引用

coalesce(t1.dPaymentIncharge_2, 0)

同时检查t1.dPaymentIncharge_1是否可以为空