开发者

Return custom value if join not successfull?

I a开发者_Go百科m trying to do a select which would return a blank '' when a join is not successfull

(when a blank '' or a '-' is encountered in column)

and return column value when it is successfull. I am using case for this but not succeeding until now. Anyone can advise a better query ?

select a.EmpName,a.deptcode,(a.deptcode||' '||(SELECT CASE(a.deptcode) WHEN a.deptcode='-' THEN '' ELSE b.deptname)) as FULLDEPTNAME from table1 a LEFT OUTER JOIN tableB b on a.deptcode=b.deptcode WHERE a.empNo=12;


(when a blank '' or a '-' is encountered in column)

If a join is unsuccessful, the column value will be null (not blank or hyphen).

Maybe this works better

  a.deptcode || '  ' || coalesce (b.deptname, '<missing>') as fulldeptname
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜