четверг, 9 декабря 2010 г.

Список дублей прав

select 
r.id "ID"
,R.REG_NO "РегНо"
,R.R_GROUP "Тип"
,decode(r.TYPE_CODE,r.TYPE_CODE,(select RV.NAME from rt_rights_voc rv where rv.code=r.type_code)) "ТипПрава"
,decode(r.DEPT_ID,r.DEPT_ID,(select dept.SHORT_NAME from rp_depts dept where dept.id=r.DEPT_ID)) "Отдел"
,R.CON_DESC "Опис"
,RE.CON_DESC(r.re_id) "Объект"
,(
 select wm_concat(decode(rr.DEPT_ID,rr.DEPT_ID,(select dept.SHORT_NAME from rp_depts dept where dept.id=rr.DEPT_ID))) 
  from rt_rights rr 
  where 
    rr.reg_no= r.reg_no 
    and r.dept_id <> rr.dept_id 
    and r.r_group=rr.r_group 
    and r.re_id<>rr.re_id 
    and RR.MOVED = 'Н'
) "ГдеДубл"
from 
rt_rights r
where
(
  select count(rr.id) 
  from rt_rights rr 
  where 
    rr.reg_no= r.reg_no 
    and r.dept_id <> rr.dept_id 
    and r.r_group=rr.r_group 
    and r.re_id<>rr.re_id 
    and RR.MOVED = 'Н'
)>0
and r.reg_no <> '0'
and R.MOVED = 'Н'
--and R.DEPT_ID=10
order by r.dept_id, r.reg_no

Комментариев нет:

Отправить комментарий