SQL Server: join If -


i have below table. need create join ownername captured first , if null use secondaryname

from table  left join hr on a.ownername = hr.id --or a.secondaryname = hr.id  not work , hr.active = y 

table a

 id     secondaryname    ownername      1        jaj              null           2        jat              jat  3        joa              nel 

table hr table

 role            id     active  senior          jat     y  senior          nel     y  specialist      jaj     y 

you can use coalesce

left join hr on coalesce(a.ownername, a.secondaryname) = hr.id 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -