sql server - Case with Select and Null Check -


select a.agentid,        case(select acs.isconnected             rmm.tblagentconnectionstatus acs             acs.agentname = a.agentname)         when 1 'true'         when 0 'false'         when null 'false'         end connectionstatus sentilan2.rmm.tblagent order agentname asc 

i have above, results in connectionstatus being null when no corresponding row in tblagent.

is possible result false when column null.

current output

agentid                                 connectionstatus 010d0206-5d8c-4ab1-90b6-7bd0c2773e22    true ca4c48dd-3d2e-4948-9f93-254cdf081658    true 1db90ee5-d96a-4071-8f51-26b3130ec6d4    null aca694d0-0c1d-45ba-80dd-273f41bd70b1    null 941b539b-7ca0-4472-abcd-2777ae8b2e5d    null 1e7dda4d-c119-4e47-8478-277952024fd1    null 

i'd nulls false.

you use coalesce() or isnull() substitute value null:

select a.agentid,        case coalesce((select acs.isconnected             rmm.tblagentconnectionstatus acs             acs.agentname = a.agentname),0)         when 1 'true'         when 0 'false'         end connectionstatus sentilan2.rmm.tblagent order agentname asc 

or else 'false':

select a.agentid,        case (select acs.isconnected             rmm.tblagentconnectionstatus acs             acs.agentname = a.agentname)         when 1 'true'         else 'false'         end connectionstatus sentilan2.rmm.tblagent order agentname asc 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -