oracle - case statement with in case statement -
i not sure kind of statement need in order need do. add case statement after case statement have. bellow case statement.
case when locoff.ext_srv_polygon in ('bof', 'cda', 'col', 'dac', 'gos', 'kel', 'klf', 'lag', 'lec', 'med', 'pum', 'rit', 'ros', 'san', 'spo') 'gas' when locoff.ext_srv_polygon in ('cdc', 'coc', 'dav', 'dpc', 'grc', 'kec', 'lcc', 'otc', 'pac', 'sac', 'spc') 'electric' else 'missing' end type,
i if ext_distworktype gc or gt , type electric, give me type says wrong polygon or if ext_distworktype ec, es, or et , type gas give me type wrong polygon.
here full query:
select wo.wonum "work order", wo.location "location", wo.status "status", wo.description, wo.actfinish "actual finish", wo.parent "parent wo", wo.worktype "work type", case when wo.reportdate null to_date('29-jan-15 00:00:00', 'dd-mon-yy hh24:mi:ss') else wo.reportdate end "reported date", wo.siteid "site", case when wo.actfinish null greatest(trunc(to_date(sysdate, 'dd-mon-yy hh24:mi:ss') - to_date(wo.reportdate, 'dd-mon-yy hh24:mi:ss'), 6), 0) when wo.status not in ('comp') greatest(trunc(to_date(sysdate, 'dd-mon-yy hh24:mi:ss') - to_date(wo.reportdate, 'dd-mon-yy hh24:mi:ss'), 6), 0) when wo.status in ('comp') greatest(trunc(to_date(wo.actfinish, 'dd-mon-yy hh24:mi:ss') - to_date(wo.reportdate, 'dd-mon-yy hh24:mi:ss'), 6), 0) end "age", wo.ext_distworktype, locoff.ext_office, case when locoff.ext_srv_polygon in ('bof', 'cda', 'col', 'dac', 'gos', 'kel', 'klf', 'lag', 'lec', 'med', 'pum', 'rit', 'ros', 'san', 'spo') 'gas' when locoff.ext_srv_polygon in ('cdc', 'coc', 'dav', 'dpc', 'grc', 'kec', 'lcc', 'otc', 'pac', 'sac', 'spc') 'electric' else 'missing' end type, locoff.ext_statecode, wo.ownergroup, wo.ext_jobcode locations locoff right join workorder wo on wo.location = locoff.location wo.status not in ('close', 'waiv', 'can', 'rej', 'revoked') , locoff.siteid = 'ops' , wo.ext_jobcode not 'a%' , wo.e`enter code here`xt_jobcode not 'b%' , wo.ext_jobcode not in ('k008','k009','i006','i007','i008');
you can nest case expressions if want modify existing column value (rather adding separate column 'wrong polygon' message):
case when locoff.ext_srv_polygon in ('bof', 'cda', 'col', 'dac', 'gos', 'kel', 'klf', 'lag', 'lec', 'med', 'pum', 'rit', 'ros', 'san', 'spo') case when wo.ext_distworktype in ('ec', 'es', 'et') 'wrong polygon' else 'gas' end when locoff.ext_srv_polygon in ('cdc', 'coc', 'dav', 'dpc', 'grc', 'kec', 'lcc', 'otc', 'pac', 'sac', 'spc') case when wo.ext_distworktype in ('gc', 'gt') 'wrong polygon' else 'electric' end else 'missing' end type,
quick sql fiddle demos same made-up data; your original case , this nested case, gives:
ext ex type --- -- ------------- bof gc gas cda gt gas spo es wrong polygon cdc ec electric coc et electric spc gc wrong polygon
this bit simpler trying second step interprets type
value, because can't refer column alias in same level of query; need make existing query inline view.
Comments
Post a Comment