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

Отчет по Выдачи на ССД

Общие цифры
select
(case
 when qr.DECISION='В' then 'Выдано'
 when qr.DECISION='О' then 'Отказано'
 when qr.DECISION='У' then 'Уведомить'
 else 'Неизветно'
end) "Решение"

,count(qr.id) "Кол-во"
from
qu_applications qa
,QU_REFERENCES qr
where
qr.QU_APP_ID=qa.id

and qa.dept_id=0


and qr.R_DATE between TO_DATE ('&start#', 'dd.mm.yyyy') and TO_DATE ('&end#', 'dd.mm.yyyy')
group by qr.DECISION 


Платные
select
(case
 when qr.DECISION='В' then 'Выдано'
 when qr.DECISION='О' then 'Отказано'
 when qr.DECISION='У' then 'Уведомить'
 else 'Неизветно'
end) "Решение"

,qrv.NAME 
,count(qr.id) "Кол-во"

from
qu_applications qa
,QU_REFERENCES qr
,QU_REFERENCE_VOC qrv
where
qr.QU_APP_ID=qa.id

and qa.dept_id=0
and qa.FREE_INFO='Н'
and qrv.CODE=qr.TYPE_CODE
and qr.R_DATE between TO_DATE ('&start#', 'dd.mm.yyyy') and TO_DATE ('&end#', 'dd.mm.yyyy')
group by qr.DECISION , qrv.NAME 

Бесплатно
select
(case
 when qr.DECISION='В' then 'Выдано'
 when qr.DECISION='О' then 'Отказано'
 when qr.DECISION='У' then 'Уведомить'
 else 'Неизветно'
end) "Решение"

,qrv.NAME
,decode(qa.ENT_ROLE,qa.ENT_ROLE,(select crc.RV_ABBREVIATION from cg_ref_codes crc where crc.RV_DOMAIN = 'QU РОЛЬ ЗАЯВИТЕЛЯ (СПИСОК)' and  crc.RV_LOW_VALUE =qa.ENT_ROLE)) "Субъект"
 
,count(qr.id) "Кол-во"

from
qu_applications qa
,QU_REFERENCES qr
,QU_REFERENCE_VOC qrv
where
qr.QU_APP_ID=qa.id

and qa.dept_id=0
and qa.FREE_INFO='Д'
and qrv.CODE=qr.TYPE_CODE
and qr.R_DATE between TO_DATE ('&start#', 'dd.mm.yyyy') and TO_DATE ('&end#', 'dd.mm.yyyy')
group by qr.DECISION , qrv.NAME , qa.ENT_ROLE 

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

Дубли книг

список книг дублей за 2008год
select
V.ID
,V.R_TYPE
,V.NO
,decode(v.DEPT_ID,v.DEPT_ID,(select dept.SHORT_NAME from rp_depts dept where dept.id=v.DEPT_ID)) "Отдел"
from
vol_volumes v  
where
v.no like '%2008%'
and (
    select 
    count(VV.ID)
    from
    vol_volumes vv  
    where
    vv.no = v.no
    and vv.r_type=v.r_type
    and vv.id<>V.ID
    )>0

order by v.no,v.r_type


Список КУВД
select 
ap.id "ID"
,AP.NO "КУВД" 
,decode(v.DEPT_ID,v.DEPT_ID,(select dept.SHORT_NAME from rp_depts dept where dept.id=v.DEPT_ID)) "Отдел"
from
app_applications ap
where
ap.vol_id in
(
    select
    V.ID
    from
    vol_volumes v  
    where
    v.no like '%2008%'
    and V.R_TYPE='APP'
    and (
            select 
            count(VV.ID)
            from
            vol_volumes vv  
            where
            vv.no = v.no
            and vv.r_type=v.r_type
            and vv.id<>V.ID
        )>0
)
and 
(
    select 
    count(ap2.id) 
    from
    app_applications ap2
    where
    ap2.no=ap.no
    and AP.ID<>AP2.ID
)>0

понедельник, 13 декабря 2010 г.

Транслит

UPDATE reestr
SET
synom=
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(namecave
,'А','A')
,'Б','B')
,'В','V')
,'Г','G')
,'Д','D')
,'Е','E')
,'Ё','Yo')
,'Ж','Zh')
,'З','Z')
,'И','I')
,'К','K')
,'Л','L')
,'М','M')
,'Н','N')
,'О','O')
,'П','P')
,'Р','R')
,'С','S')
,'Т','T')
,'У','U')
,'Ф','F')
,'Х','Kh')
,'Ц','Ts')
,'Ч','Ch')
,'Ш','Sh')
,'Щ','Sch')
,'Ъ','')
,'Ы','Y')
,'Ь','')
,'Э','E')
,'Ю','Yu')
,'Я','Ya')
,'а','a')
,'б','b')
,'в','v')
,'г','g')
,'д','d')
,'е','e')
,'ё','yo')
,'ж','zh')
,'з','z')
,'и','i')
,'й','y')
,'к','k')
,'л','l')
,'м','m')
,'н','n')
,'о','o')
,'п','p')
,'р','r')
,'с','s')
,'т','t')
,'у','u')
,'ф','f')
,'х','kh')
,'ц','ts')
,'ч','ch')
,'ш','sh')
,'щ','sch')
,'ъ','')
,'ы','y')
,'ь','')
,'э','e')
,'ю','yu')
,'я','ya')
,' ','')

в одной строке несколько строк

select 
 o.id
 ,(select wm_concat(' '||r.reg_no) from rt_rights r where r.re_id=o.id) "rt"
from
 re_objects o
 
where
 o.id=2642000


id

rt

2642000

19-01/00-1/000-01, 19-01/00-1/000-00/2, 19-01/00-1/000-100

четверг, 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

среда, 1 декабря 2010 г.

Удаление пустых объектов

Удаление права
select 
r.id
,r.re_id
,r.REG_NO
,r.TYPE_CODE
,r.SECTION
,r.R_GROUP
,r.PART
,r.CON_DESC
,r.RS_PERIOD
,r.RS_S_DATE
,r.RS_E_DATE
,r.SERV_OWNER
,r.BRG_ID
,r.RE_PRICE
,r.RT_CLAIM
,r.RT_LEGAL_CLAIM
,r.LEGALITY
,r.S_DATE
,r.S_REG_ID
,r.S_REMARK
,r.E_DATE
,r.E_REG_ID
,r.E_REMARK
,r.STATUS
,r.DEPT_ID
,r.MOVED
,r.INSERTED
,r.INSERTED_BY
,r.UPDATED
,r.UPDATED_BY
,r.CURRENCY
,r.PRICE_DESC
,to_char(r.RS_DESC) "RS_DESC"
,r.PART_MUCH_HOUSE 
from
rt_rights r
where
r.re_id in (select o.id from re_objects o where o.obj_num = '(неизвестно)') 
and R.TYPE_CODE in (205,206,260)
and r.INSERTED < to_date('07.06.2007')
Удаление связи RT_RS
select * 
--delete
from rt_rs q
where 
q.rt_id in
(
 select r.id
 from
 rt_rights r
 where
 r.re_id in (select o.id from re_objects o where o.obj_num = '(неизвестно)') 
 and R.TYPE_CODE in (205,206,260)
 and r.INSERTED < to_date('07.06.2007')
)
Удаление связи APP_RT
select * 
--delete
from APP_RT q
where 
q.rt_id in
(
 select r.id
 from
 rt_rights r
 where
 r.re_id in (select o.id from re_objects o where o.obj_num = '(неизвестно)') 
 and R.TYPE_CODE in (205,206,260)
 and r.INSERTED < to_date('07.06.2007')
)

Удаление связи RT_ENT
select * 
--delete
from RT_ENT q
where 
q.rt_id in
(
 select r.id
 from
 rt_rights r
 where
 r.re_id in (select o.id from re_objects o where o.obj_num = '(неизвестно)') 
 and R.TYPE_CODE in (205,206,260)
 and r.INSERTED < to_date('07.06.2007')
)
Удаление связи DOC_REL
select * 
--delete
from DOC_REL q
where 
--q.rt_S_id in
q.rt_e_id in
(
 select r.id
 from
 rt_rights r
 where
 r.re_id in (select o.id from re_objects o where o.obj_num = '(неизвестно)') 
 and R.TYPE_CODE in (205,206,260)
 and r.INSERTED < to_date('07.06.2007')
)

Удаление Налоговая
delete
select * 
--delete
from NAL_EXPORTS_DET q
where 
q.rt_id in
(
 select r.id
 from
 rt_rights r
 where
 r.re_id in (select o.id from re_objects o where o.obj_num = '(неизвестно)') 
 and R.TYPE_CODE in (205,206,260)
 and r.INSERTED < to_date('07.06.2007')
)
Удаление ПРАВ
delete
from
rt_rights r
where
r.re_id in (select o.id from re_objects o where o.obj_num = '(неизвестно)') 
and R.TYPE_CODE in (205,206,260)
and r.INSERTED < to_date('07.06.2007')
------------------------- проверка на связи
select
o.ID "ID"
,O.CAD_NUM||O.OBJ_NUM "КадУслНо"
,o.name "Name"
,O.ADR_PRN_DESC "ADR"
,(select '('||count(rps.id)||') '||max(rps.ID) from re_purposes rps where rps.re_id = o.id ) "RE_PURPOSES"
,(select '('||count(r.id)||') '||max(r.ID) from rt_rights r where r.re_id = o.id ) "RT_RIGHTS"
,(select '('||count(dr.id)||') '||max(dr.ID) from doc_rel dr where dr.re_s_id = o.id ) "doc_rel_S"
,(select '('||count(dr.id)||') '||max(dr.ID) from doc_rel dr where dr.re_e_id = o.id ) "doc_rel_E"
,(select '('||count(are.id)||') '||max(are.ID) from app_re are where are.re_id = o.id ) "APP_RE"
,(select '('||count(arc.id)||') '||max(arc.ID) from ar_re_candidats arc where arc.re_id = o.id ) "ar_re_candidats"
,(select '('||count(qrc.id)||') '||max(qrc.ID) from qu_re_candidats qrc where qrc.re_id = o.id ) "qu_re_candidats"
,(select '('||count(arv.id)||') '||max(arv.ID) from arch_re_values arv where arv.re_id = o.id ) "arch_re_values"
,(select '('||count(art.id)||') '||max(art.ID) from arch_rt_rights art where art.re_id = o.id ) "arch_rt_rights"
,(select '('||count(cc.id)||') '||max(cc.ID) from cse_cases cc where cc.re_id = o.id ) "CSE_CASES"

from
re_objects o
where
o.id=69554001
удаляем связи
DELETE FROM qu_re_candidats WHERE ID =29062001;
Удаляем связи app_re
select *
--delete
from
 app_re q
where
q.re_id in 
    (
    select
        o.id
    from
        re_objects o
    where
        o.id not in (select r.re_id from rt_rights r )  --Права
        and o.obj_num = '(неизвестно)'
    )
    and Q.INSERTED < to_date('07.06.2007')
Список объектов без прав
select
*
from
re_objects o
where
--o.id not in (select are.re_id from app_re are ) --КУВД
--and o.id not in (select qrc.re_id from qu_re_candidats qrc ) --КВИ
--and o.id not in (select arc.re_id from ar_re_candidats arc ) --КА
o.id not in (select r.re_id from rt_rights r )  --Права
and o.INSERTED < to_date('07.06.2007')
Удаляем связи ar_re_candidats
select *
--delete
from
 ar_re_candidats q
where
q.re_id in
    (
    select
        o.id
    from
        re_objects o
    where
        o.id not in (select r.re_id from rt_rights r )  --Права
        and o.obj_num = '(неизвестно)'
    )
    and
    (
    Q.INSERTED < to_date('07.06.2007')
    or Q.STATE in ('П','У')
    )
Удаляем связи qu_re_candidats
select *
--delete 
from
 qu_re_candidats q
where
q.re_id in 
    (
    select
        o.id
    from
        re_objects o
    where
        o.id not in (select r.re_id from rt_rights r )  --Права
        and o.obj_num = '(неизвестно)'
        and o.INSERTED < to_date('07.06.2007')
    )
Удаляем связи re_purposes
select *
--delete 
from
 re_purposes q
where
q.re_id in 
    (
    select
        o.id
    from
        re_objects o
    where
        o.id not in (select r.re_id from rt_rights r )  --Права
        and o.obj_num = '(неизвестно)'
        and o.INSERTED < to_date('07.06.2007')
    )
Удаляем связи cse_orders
select *
--delete
from
 cse_orders o
where
o.csf_id in 
    (
select id
--delete
from
 cse_folders f
where
f.cse_id in 
    (
select q.id
--delete
from
 cse_cases q
where
q.re_id in 
    (
    select
        o.id
    from
        re_objects o
    where
        o.id not in (select r.re_id from rt_rights r )  --Права
        and o.obj_num = '(неизвестно)'
        and o.INSERTED < to_date('07.06.2007')
    )
    
    )
        
    )
Удаляем связи cse_folders
select *
--delete
from
 cse_folders f
where
f.cse_id in 
    (
select q.id
--delete
from
 cse_cases q
where
q.re_id in 
    (
    select
        o.id
    from
        re_objects o
    where
        o.id not in (select r.re_id from rt_rights r )  --Права
        and o.obj_num = '(неизвестно)'
        and o.INSERTED < to_date('07.06.2007')
    )
    
    )
   and (select count(cd.id) from cse_doc cd where cd.csf_id=f.id)=0  
Удаляем связи cse_cases
select q.*
--delete
,(select count(c.id)from cse_folders c where c.cse_id=q.id) "cse_folders"
from
 cse_cases q
where
q.re_id in 
    (
    select
        o.id
    from
        re_objects o
    where
        o.id not in (select r.re_id from rt_rights r )  --Права
        and o.obj_num = '(неизвестно)'
        and o.INSERTED < to_date('07.06.2007')
    )
and (select count(cd.id) from cse_folders cd where cd.cse_id=q.id)=0 
Удаление документов doc_rel
select *
--delete
from
 doc_rel q
where
q.re_S_id in
--q.re_E_id in
    (
    select
        o.id
    from
        re_objects o
    where
        o.id not in (select r.re_id from rt_rights r )  
        and o.obj_num = '(неизвестно)'
        and O.INSERTED < to_date('07.06.2007')
    )
Удаляем выгрузки объектов в налоговую
--delete
select * 
--delete
from NAL_EXPORTS_DET q
where
q.re_id in
    (
    select
        o.id
    from
        re_objects o
    where
        o.id not in (select r.re_id from rt_rights r )  
        and o.obj_num = '(неизвестно)'
        and O.INSERTED < to_date('11.07.2007')
    )
    --and q.dept_id=6
Удаляем re_objects
select id , o.adr_desc
 
--delete 
--,(select '('||count(arc.id)||') '||max(arc.ID) from ar_re_candidats arc where arc.re_id = o.id ) "ar_re_candidats"
--,(select '('||count(qrc.id)||') '||max(qrc.ID) from qu_re_candidats qrc where qrc.re_id = o.id ) "qu_re_candidats"
--,(select count(dr.id) from doc_rel dr where dr.re_s_id=o.id) "re_s_id" 
--,(select count(dr.id) from doc_rel dr where dr.re_e_id=o.id) "re_e_id" 
--,(select count(dr.id) from cse_cases dr where dr.re_id=o.id) "cse_cases" 
--,(select count(dr.id) from ARCH_RE_OBJECTS dr where dr.ARCH_PAR_ID=o.id) "ARCH_PAR_ID" 
--,(select count(dr.id) from ARCH_RE_OBJECTS dr where dr.RE_INCLUDE_ID=o.id) "arch_RE_INCLUDE_ID" 
--,(select count(dr.id) from RE_OBJECTS dr where dr.RE_INCLUDE_ID=o.id) "RE_INCLUDE_ID" 
 
from
re_objects o
where
--o.id not in (select are.re_id from app_re are ) --КУВД
--and o.id not in (select qrc.re_id from qu_re_candidats qrc ) --КВИ
--and o.id not in (select arc.re_id from ar_re_candidats arc ) --КА
--AND (select count(dr.id) from cse_cases dr where dr.re_id=o.id)>0
--and o.id not in (select dr.re_s_id from doc_rel dr )  --
 
o.id not in (select r.re_id from rt_rights r )  --Права
and o.obj_num = '(неизвестно)'
and o.INSERTED < to_date('10.07.2007')
 
and (select count(dr.id) from ARCH_RE_OBJECTS dr where dr.RE_INCLUDE_ID=o.id) =0
and (select count(dr.id) from ARCH_RE_OBJECTS dr where dr.ARCH_PAR_ID=o.id) =0
and (select count(dr.id) from RE_OBJECTS dr where dr.RE_INCLUDE_ID=o.id) =0
and (select count(dr.id) from APP_RE dr where dr.RE_ID=o.id) =0
and (select count(dr.id) from AR_RE_CANDIDATS dr where dr.RE_ID=o.id) =0
and (select count(dr.id) from cse_cases dr where dr.RE_ID=o.id) =0