How to default a value in subquery result?

Kasia Wichrowska :

Hopefully this is a simple one but I am most likely over complicating this for myself. Purpose of this code is to find previous operation name within a specified list of operations that is still open and returning it. If it's closed to say 'CLOSED'.

So far I'm using subquery to get the correct operation name, as expected I'm getting some null results which indicates to me that operation is closed. I wanted to wrap my subquery into a case statement to say something along the lines of CASE WHEN it's null then 'CLOSED' else operation_name end.

(select work_center_no 
  from shop_order_operation  
  where order_no = so.order_no 
  and release_no = so.release_no 
  and sequence_no = so.sequence_no 
  and work_center_no in ('CNC','EXPF','LS3M','LS4M','LS6M','PLAS','SAW','TBPL','EXSAW')
  and oper_status_code in ('Released','In Process') order by operation_no fetch first 1 row only )

Above is my subquery. Hope this makes sense.

Thanks! K

Lajos Arpad :

You can nicely default a value using IFNULL, just change your select clause to this:

select IFNULL(work_center_no, 'CLOSED')

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=5633&siteId=1