开发者

IfNull function in mysql doesnt seem to work for me

开发者 https://www.devze.com 2022-12-20 12:36 出处:网络
IfNull function in mysql doesnt seem to work for me.... When i executed this query select t1.dAccHeader_id,t1.dAccHeaderName,t1.dAccHeaderAcronym,

IfNull function in mysql doesnt seem to work for me.... When i executed this query

select t1.dAccHeader_id,t1.dAccHeaderName,t1.dAccHeaderAcronym,
t2.dDesignationName as incharge1,
t开发者_如何学Python3.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'

Here is my table,

IfNull function in mysql doesnt seem to work for me

Any sugesstion...


You can try using coalesce function

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

if your id is a number you can also remove the quote:

coalesce(t1.dPaymentIncharge_2, 0)

Check also if your t1.dPaymentIncharge_1 can be null

0

精彩评论

暂无评论...
验证码 换一张
取 消