zOs/SQL/EXCEPSEL

with ex as
( select  pri,
    db,  case when posstr(db,  '*') > 0
              then posstr(db,  '*') - 1 else 8 end dbLen,
    ts,  case when posstr(ts,  '*') > 0
              then posstr(ts,  '*') - 1 else 8 end tsLen,
    ix,  case when posstr(ix,  '*') > 0
              then posstr(ix,  '*') - 1 else 16 end ixLen,
    fun, case when posstr(fun, '*') > 0
              then posstr(fun, '*') else 8 end funLen,
    code, wert, info,
         char(right('000' || strip(char(pri)), 4) || ' '
         || translate(db || ts || ix || fun, x'01', '*') , 44) cat
    from gdb9998.except
)
select e.*, s.*
     from sysibm.systablespace s, ex e
     where s.dbName = 'DGDB9998' and
         e.cat = (select max(cat) from ex f where
                      left(f.db, f.dbLen) = left(s.dbName, f.dbLen)
                 and  left(f.ts, f.tsLen) = left(s.Name, f.tsLen)
                 and  f.ix = ''
                 and  f.fun like 'GB%'
                 )
  order by cat