select paginado.* from (
select rownum rn, antecedenteComprobacionTabs.* from (select decode(porintv, null, 0, 1) + decode(pormat, null, 0, 1) + decode(porcls, null, 0, 1) + decode(porproj, null, 0, 1) + decode(porprojori, null, 0, 1) as sumcoincidencias,
antecedenteRecuperado.* from (select datos.* from (select
idcondrptanteced,
idasunto,
cdprojori,
nmprorgjudori,
nmprorgjuddest,
cdtipoprojori,
cdtipoprojdest,
cdestadoregistro,
itasuntoenmovimiento,
cdufojactual,
dsufojactual,
cdufojrpt,
dsufojrpt,
cdtipoasunto,
nmregistroofre,
anyoregistroofre,
cdtipoprojoriext,
numprojoriext,
anyoprojoriext,
itsecretosumario,
cdufojactualDestinoCLS,
cdufojrptDestinoCLS,
cdufojori,
replace(replace(xmlagg
(xmlelement (e, nombreintv,'|',itrol,'|',cdtipointvproj,'*',cdclsrpt,'*',
cdtipodelimate,'|',cdfamidelimate,'|',dstipodelimate,'*',
cdtipoproj,'|',dstipoproj,'*',cdprojori,'*')),'',''),'','') as datosAntecedentes,
replace(replace(xmlagg
(xmlelement (e, decode(nombreintv, null, null, 1))),' ',''),'','') as porintv,
replace(replace(xmlagg
(xmlelement (e, decode(cdtipodelimate, null, null, 1))),' ',''),'','') as pormat,
replace(replace(xmlagg
(xmlelement (e, decode(cdclsrpt, null, null, 1))),' ',''),'','') as porcls,
replace(replace(xmlagg
(xmlelement (e, decode(cdtipoproj, null, null, 1))),' ',''),'','') as porproj,
replace(replace(xmlagg
(xmlelement (e, decode(cdprojori, null, null, decode(cdprojori, '/', null, 1)))),' ',''),'','') as porprojori,
prioridad,
(select decode(count(*), 0, 0, 1) from ofre_condrptanteced cond, ofre_condrptanteced_intv intva where cond.idcondrpt = :idcondrpt and INTVA.IDCONDRPTANTECED = cond.idcondrptanteced and cond.fcbaja is null and intva.fcbaja is null and prioridadcomparar = cond.prioridad) +
(select decode(count(*), 0, 0, 1) from ofre_condrptanteced cond, ofre_condrptanteced_clsreparto clsa where cond.idcondrpt = :idcondrpt and clsA.IDCONDRPTANTECED = cond.idcondrptanteced and cond.fcbaja is null and clsa.fcbaja is null and prioridadcomparar = cond.prioridad) +
(select decode(count(*), 0, 0, 1) from ofre_condrptanteced cond, ofre_condrptanteced_materia clsa where cond.idcondrpt = :idcondrpt and clsA.IDCONDRPTANTECED = cond.idcondrptanteced and cond.fcbaja is null and clsa.fcbaja is null and prioridadcomparar = cond.prioridad) +
(select decode(count(*), 0, 0, 1) from ofre_condrptanteced cond, ofre_condrptanteced_projori clsa where cond.idcondrpt = :idcondrpt and clsA.IDCONDRPTANTECED = cond.idcondrptanteced and cond.fcbaja is null and clsa.fcbaja is null and clsa.itprojori = 'S' and prioridadcomparar = cond.prioridad) +
(select decode(count(*), 0, 0, 1) from ofre_condrptanteced cond, ofre_condrptanteced_tipoproj clsa where cond.idcondrpt = :idcondrpt and clsA.IDCONDRPTANTECED = cond.idcondrptanteced and cond.fcbaja is null and clsa.fcbaja is null and prioridadcomparar = cond.prioridad) con
from
(
SELECT
prioridad as prioridadcomparar,
idcondrptanteced,
asuant.idasunto,
antecedente.cdufojori || antecedente.cdtipoprojori || antecedente.nmprorgjudori || '/' || antecedente.anyoprorgjudori cdprojori,
-- rownum rn,
lpad(antecedente.nmprorgjudori, 7, '0') || '/' || antecedente.anyoprorgjudori nmprorgjudori,
lpad(pjdest.NMPRORGJUD, 7, '0') || '/' || pjdest.anyoPRORGJUD nmprorgjuddest,
asuant.cdtipoprojori cdtipoprojori,
pjdest.cdtipoproj cdtipoprojdest,
aufoj.cdestadoregistro, -- 'ENV' o 'REP'
asuant.itasuntoenmovimiento, -- 'S' o 'N'
asuant.cdufojactual,
(SELECT UF.DSUFOJ FROM INTS_C_UFORGJUDICIAL UF
WHERE UF.CDUFOJ = asuant.cdufojactual) as dsufojactual,
asuant.cdufojrpt,
(SELECT UF.DSUFOJ FROM INTS_C_UFORGJUDICIAL UF
WHERE UF.CDUFOJ = asuant.cdufojrpt) as dsufojrpt,
asuant.cdtipoasunto, asuant.nmregistroofre, asuant.anyoregistroofre,
asuant.cdtipoprojoriext, asuant.numprojoriext, asuant.anyoprojoriext,
(select nvl(
(select 'S' from dual
where
((sysdate between asuant.FCINISECRETOACT and asuant.FCFINSECRETOACT)
or (asuant.FCINISECRETOACT < idverclsrpt =" des.idverclsrpt" idasunto =" :idasunto" idverclsrpt =" des.idverclsrpt" idasunto =" :idasunto" idcondrpt =" ant.idcondrpt" idcondrpt =" :idcondrpt" idcondrptanteced =" ant.idcondrptanteced" idasunto =" :idasunto" itprojori =" 'S'" idcondrpt =" ant.idcondrpt" idcondrpt =" :idcondrpt" idcondrptanteced =" ant.idcondrptanteced" idconfigreparto =" antcls.cdconfigreparto" idconfigreparto =" antcls.cdconfigreparto" idclsrpt =" CONF.IDCLSRPT" idcondrpt =" :idcondrpt" cdinterviniente =" intv.cdinterviniente" cdintvasunto =" INTV.CDINTVASUNTO" idcondrptanteced =" antintv.idcondrptanteced" idasunto =" :idasunto" cdtipointvproj =" tipointvproj.cdtipointvproj" idcondrpt =" ant.idcondrpt" idcondrpt =" :idcondrpt" idcondrptanteced =" ant.idcondrptanteced" cdfamidelimate =" antmat.cdfamidelimate" cdtipodelimate =" antmat.cdtipodelimate" idcondrpt =" ant.idcondrpt" idcondrpt =" :idcondrpt" idcondrptanteced =" ant.idcondrptanteced" cdtipoproj =" ANTTIP.CDTIPOPROJ" cdufoj =" asuant.cdufojactual" idasunto =" asuant.idasunto"> 'ANU')
and pjdest.idasunto (+) = asuant.idasunto
AND (:idasuntofiltro = asuant.idasunto or (
-- búsqueda de antecedentes sin idasuntofiltro
:idasuntofiltro is null
-- El asunto a repartir no puede ser antecedente
and asuant.idasunto <> :idasunto
-- Exenciones de reparto
and not exists (
select
*
from
OFRE_INTVEXENRPT exen,
ints_asunto_intvasu intvasu
where
exen.cdufoj = :cdufojorr
AND exen.cdinterviniente = intvasu.cdinterviniente
AND intvasu.idasunto = asuant.idasunto
)
-- condiciones funcionales 09/2009 -- corregido 19/04/2010
and
exists (
select
cdufoj
from
OFRE_VERCLSREPARTO_DESTINO des,
ints_asunto asu
where
asu.idverclsrpt = des.idverclsrpt
and asu.idasunto = :idasunto
and (des.cdufoj = asuant.cdufojrpt
or des.cdufoj = asuant.cdufojactual
or (asuant.cdufojactual = :cdufojorr and asuant.cdufojrpt is null))
)
-- condicion de número de límite de registros
AND (antecedente.nmlimitereg is null --quitado idasuntofiltro
or antecedente.nmlimitereg = 0
or antecedente.diasvalidez is null
or antecedente.diasvalidez = 0
or antecedente.nmlimitereg >
(SELECT COUNT (*)
FROM ints_asunto asu
WHERE fcpresentacion > (SYSDATE - antecedente.diasvalidez)
and asu.cdufojrpt = asuant.cdufojrpt)
)
AND ( --dias de validez
(antecedente.diasvalidez is null
or antecedente.diasvalidez = 0
or
antecedente.diasvalidez > (SYSDATE - asuant.fcpresentacion))
AND
(
(
--Buscamos los intervinientes con el mismo tipo de intervención
EXISTS (
SELECT *
FROM
ints_asunto_intvasu intv,
INTS_C_TIPOINTVPROJ ipro
WHERE
intv.fcbaja IS NULL
and ipro.cdtipointvproj = intv.cdtipointvproj
and intv.cdinterviniente = antecedente.cdinterviniente
and intv.idasunto = asuant.idasunto
and
-- se busca la coincidencia del criterio en el asunto a repartir
(
(itasuntoregistro is null or itasuntoregistro = 'N')
or
(
(antecedente.cdtipointvprojasu = antecedente.cdtipointvproj or antecedente.cdtipointvproj is null)
and
(antecedente.itrolasu = antecedente.itrol or antecedente.itrol is null)
)
)
and
-- se busca la coincidencia del criterio en el antecedente
(
(itasuntoantecedente is null or itasuntoantecedente = 'N')
or
(
(intv.cdtipointvproj = antecedente.cdtipointvproj or antecedente.cdtipointvproj is null)
and
(ipro.itrol = antecedente.itrol or antecedente.itrol is null)
)
)
)
)-- fin OR de tipo de intervención
OR (
-- antecedentes por materia
asuant.cdfamidelimate = antecedente.cdfamidelimate and antecedente.cdtipodelimate is null
or asuant.cdtipodelimate = antecedente.cdtipodelimate and antecedente.cdfamidelimate is null
or asuant.cdfamidelimate = antecedente.cdfamidelimate and asuant.cdtipodelimate = antecedente.cdtipodelimate
)
OR (-- por tipo de procedimiento
pjdest.cdtipoproj = antecedente.cdtipoproj
)
OR (
-- por clase de reparto
asuant.idverclsrpt = antecedente.idverclsrpt
)
OR (
-- por procedimiento origen
asuant.idasuntoori = antecedente.idasuntoori
or
asuant.cdufojori = antecedente.cdufojori
and asuant.cdtipoprojori = antecedente.cdtipoprojori
and asuant.nmprorgjudori = antecedente.nmprorgjudori
and asuant.anyoprorgjudori = antecedente.anyoprorgjudori
)
)
)
) )
) group by
prioridad,
idcondrptanteced,
idasunto,
cdprojori,
nmprorgjudori,
nmprorgjuddest,
cdtipoprojori,
cdtipoprojdest,
cdestadoregistro,
itasuntoenmovimiento,
cdufojactual,
dsufojactual,
cdufojrpt,
dsufojrpt,
cdtipoasunto,
nmregistroofre,
anyoregistroofre,
cdtipoprojoriext,
numprojoriext,
anyoprojoriext,
itsecretosumario,
cdufojactualDestinoCLS,
cdufojrptDestinoCLS,
cdufojori
) datos ) antecedenteRecuperado
) antecedenteComprobacionTabs
where sumcoincidencias = con
) paginado
where rn between :inicio and decode(:idasuntofiltro, null, :fin, 1)
Mostrando entradas con la etiqueta sql. Mostrar todas las entradas
Mostrando entradas con la etiqueta sql. Mostrar todas las entradas
¡Cómo crece mi hija!
Qué mal de padre que tiene que nadie se atreve a mirarla que no sea yo...
Hijo mio
Será delito o materia publicar esto aquí, pero es que no podía pasar sin que se vea esta consulta. ¡Qué orgulloso estaría Darío! XDD
SELECT asuant.idasunto,
aufoj.cdestadoregistro, -- 'ENV' o 'REP'
asuant.itasuntoenmovimiento, -- 'S' o 'N'
asuant.cdufojactual,
asuant.cdufojrpt,
asuant.cdtipoasunto, asuant.nmregistroofre, asuant.anyoregistroofre,
asuant.cdtipoprojoriext, asuant.numprojoriext, asuant.anyoprojoriext,
(select nvl(
(select 'S' from dual
where
((sysdate between asuant.FCINISECRETOACT and asuant.FCFINSECRETOACT)
or (asuant.FCINISECRETOACT < sysdate and asuant.FCFINSECRETOACT is null))),
'N')
from dual) itsecretosumario
, DECODE((select 'S' from dual where asuant.cdufojactual in ('2807953001')), 'S', 'S', 'N') as cdufojactualDestinoORR,
DECODE((select 'S' from dual where asuant.cdufojactual in ('2800542001')), 'S', 'S', 'N' ) as cdufojactualDestinoEAR,
DECODE((select 'S' from dual where asuant.cdufojrpt in ('2807953001')), 'S', 'S', 'N' ) as cdufojrptDestinoORR
, --coincidencia por interviniente
antecedente.cdintv,
antecedente.nombreintv,
antecedente.CDFUNCIONINTERVINIENTE,
antecedente.ITROL,
antecedente.CDTIPOASUNTO,
antecedente.CDTIPOINTVPROJ,
--coincidencia por materia
antecedente.CDFUNCIONMATERIA,
antecedente.CDTIPOASUNTOMATERIA,
antecedente.CDTIPODELIMATE,
antecedente.cdfamidelimate,
antecedente.dstipodelimate,
-- coincidencia tipo de procedimiento
antecedente.CDFUNCIONPROCEDIMIENTO,
antecedente.CDTIPOASUNTOPROCEDIMIENTO,
antecedente.CDTIPOPROJ,
antecedente.dstipoproj,
-- coincidencia clase de reparto
antecedente.cdconfigreparto,
asuant.idverclsrpt AS idverclsrpt,
antecedente.CDCLSRPT
FROM ( -- antecedentes por clase de reparto
SELECT
--coincidencia por interviniente
NULL AS cdintv,
null as nombreintv,
null as CDFUNCIONINTERVINIENTE,
null as ITROL,
null as CDTIPOASUNTO,
null as CDTIPOINTVPROJ,
null as DSTIPOINTVPROJ,
--coincidencia por materia
NULL AS CDFUNCIONMATERIA,
null as CDTIPOASUNTOMATERIA,
null as CDTIPODELIMATE,
null as cdfamidelimate,
null as dstipodelimate,
-- coincidencia tipo de procedimiento
NULL AS CDFUNCIONPROCEDIMIENTO,
null as CDTIPOASUNTOPROCEDIMIENTO,
null as CDTIPOPROJ,
null as dstipoproj,
-- coincidencia clase de reparto
null AS cdconfigreparto,
ver.idverclsrpt AS idverclsrpt,
cls.CDCLSRPT as CDCLSRPT,
-- resto de campos
ant.idcondrptanteced, ant.diasvalidez,
ant.nmlimitereg,
cond.idcondrpt idcondrpt,
ant.prioridad
FROM ofre_condrpt cond,
ofre_condrptanteced ant,
ofre_condrptanteced_clsreparto antcls,
ofre_verclsreparto ver,
ofre_c_clsreparto cls,
ofre_configreparto conf
WHERE cond.idcondrpt = ant.idcondrpt
AND cond.idcondrpt = '30225'
AND antcls.idcondrptanteced = ant.idcondrptanteced
AND ver.idconfigreparto = antcls.cdconfigreparto
and CONF.IDCONFIGREPARTO = antcls.cdconfigreparto
and CLS.IDCLSRPT = CONF.IDCLSRPT
and conf.fcbaja is null
and cls.fcbaja is null
and ver.fcbaja is null
and antcls.fcbaja is null
and cond.fcbaja is null
and ant.fcbaja is null
UNION ALL
-- antecedentes por interviniente
SELECT
--coincidencia por interviniente
INTV.CDINTVASUNTO AS cdintv,
null as nombreintv,
antintv.cdfuncion as CDFUNCIONINTERVINIENTE,
antintv.itrol as ITROL,
antintv.cdtipoasunto as CDTIPOASUNTOINTERVINIENTE,
antintv.CDTIPOINTVPROJ as CDTIPOINTVPROJ,
DSTIPOINTVPROJ as DSTIPOINTVPROJ,
--coincidencia por materia
NULL AS CDFUNCIONMATERIA,
null as CDTIPOASUNTOMATERIA,
null as CDTIPODELIMATE,
null as cdfamidelimate,
null as dstipodelimate,
-- coincidencia tipo de procedimiento
NULL AS CDFUNCIONPROCEDIMIENTO,
null as CDTIPOASUNTOPROCEDIMIENTO,
null as CDTIPOPROJ,
null as dstipoproj,
-- coincidencia clase de reparto
null AS cdconfigreparto,
null AS idverclsrpt,
null as CDCLSRPT,
-- resto de campos
ant.idcondrptanteced, ant.diasvalidez,
ant.nmlimitereg,
cond.idcondrpt idcondrpt,
ant.prioridad
FROM ofre_condrpt cond,
ofre_condrptanteced ant,
ofre_condrptanteced_intv antintv,
ints_asunto asu,
ints_asunto_intvasu intv,
ints_c_tipointvproj tipointvproj
WHERE
asu.idasunto = '1200151666' --el asunto a repartir
AND cond.idcondrpt = '30225'
and intv.idasunto = asu.idasunto
and intv.fcbaja is not null
and cond.idcondrpt = ant.idcondrpt
and intv.cdtipointvproj = tipointvproj.cdtipointvproj
and ( --tipo intv
ANTINTV.CDTIPOINTVPROJ = INTV.CDTIPOINTVPROJ
and antintv.itrol is null
or
-- por rol
tipointvproj.itrol = antintv.itrol
and ANTINTV.CDTIPOINTVPROJ is null
or
-- los dos
ANTINTV.CDTIPOINTVPROJ = INTV.CDTIPOINTVPROJ
and ANTINTV.CDTIPOINTVPROJ is null
)
AND antintv.idcondrptanteced = ant.idcondrptanteced
and ant.fcbaja is null
and antintv.fcbaja is null
and cond.fcbaja is null
UNION ALL
-- antecedentes por materia
SELECT
--coincidencia por interviniente
NULL AS cdintv,
null as nombreintv,
null as CDFUNCIONINTERVINIENTE,
null as ITROL,
null as CDTIPOASUNTOINTERVINIENTE,
null as CDTIPOINTVPROJ,
null as DSTIPOINTVPROJ,
--coincidencia por materia
antmat.cdfuncion AS CDFUNCIONMATERIA,
antmat.cdtipoasunto as CDTIPOASUNTOMATERIA,
antmat.cdtipodelimate as CDTIPODELIMATE,
antmat.cdfamidelimate as cdfamidelimate,
dstipodelimate as dstipodelimate,
-- coincidencia tipo de procedimiento
NULL AS CDFUNCIONPROCEDIMIENTO,
null as CDTIPOASUNTOPROCEDIMIENTO,
null as CDTIPOPROJ,
null as dstipoproj,
-- coincidencia clase de reparto
null AS cdconfigreparto,
null AS idverclsrpt,
null as CDCLSRPT,
-- resto de campos
ant.idcondrptanteced, ant.diasvalidez,
ant.nmlimitereg,
cond.idcondrpt idcondrpt,
ant.prioridad
FROM ofre_condrpt cond,
ofre_condrptanteced ant,
ofre_condrptanteced_materia antmat,
ints_c_tipodelimate mat
WHERE cond.idcondrpt = ant.idcondrpt
AND cond.idcondrpt = '30225'
AND antmat.idcondrptanteced = ant.idcondrptanteced
and mat.CDFAMIDELIMATE = antmat.cdfamidelimate
and mat.CDTIPODELIMATE = antmat.cdtipodelimate
and ant.fcbaja is null
and antmat.fcbaja is null
and cond.fcbaja is null
UNION ALL
-- antecedentes por tipo de procedimiento
SELECT
--coincidencia por interviniente
NULL AS cdintv,
null as nombreintv,
null as CDFUNCIONINTERVINIENTE,
null as ITROL,
null as CDTIPOASUNTOINTERVINIENTE,
null as CDTIPOINTVPROJ,
null as DSTIPOINTVPROJ,
--coincidencia por materia
NULL AS CDFUNCIONMATERIA,
null as CDTIPOASUNTOMATERIA,
null as CDTIPODELIMATE,
null as cdfamidelimate,
null as dstipodelimate,
-- coincidencia tipo de procedimiento
anttip.cdfuncion AS CDFUNCIONPROCEDIMIENTO,
anttip.cdtipoasunto as CDTIPOASUNTOPROCEDIMIENTO,
anttip.cdtipoproj as CDTIPOPROJ,
dstipoproj as dstipoproj,
-- coincidencia clase de reparto
null AS cdconfigreparto,
null AS idverclsrpt,
null as CDCLSRPT,
-- resto de campos
ant.idcondrptanteced, ant.diasvalidez,
ant.nmlimitereg,
cond.idcondrpt idcondrpt,
ant.prioridad
FROM ofre_condrpt cond,
ofre_condrptanteced ant,
ofre_condrptanteced_tipoproj anttip,
ints_c_tipoprorgjud tipoproj
WHERE cond.idcondrpt = ant.idcondrpt
AND cond.idcondrpt = '30225'
AND anttip.idcondrptanteced = ant.idcondrptanteced
and TIPOPROJ.CDTIPOPROJ = ANTTIP.CDTIPOPROJ
and cond.fcbaja is null
and anttip.fcbaja is null
and ant.fcbaja is null order by prioridad asc) antecedente,
ints_asunto asuant,
ints_asunto_ufoj aufoj,
ints_prorgjud proj
WHERE
-- casamientos ^^
asuant.fcbaja IS NULL
AND asuant.idverclsrpt IS NOT NULL
AND asuant.cdufojrpt IS NOT NULL
AND aufoj.cdufoj = asuant.cdufojactual
AND aufoj.idasunto = asuant.idasunto
AND aufoj.cdestadoregistro <> 'ANU'
AND asuant.cdprojori = proj.cdproj(+)
-- condiciones funcionales 09/2009
AND ( aufoj.cdestadoregistro = 'REP' -- repartido y no enviado
OR ( aufoj.cdestadoregistro = 'ENV' -- enviado
AND (
asuant.itasuntoenmovimiento = 'N'
--aceptado en destino
AND ( asuant.cdufojactual IN ('2807953001')
OR ( asuant.cdufojactual IN
('2800542001')
AND asuant.cdufojrpt IN ('2807953001')
)
)
OR ( -- no aceptado en destino, itasuntoenmovimiento='S'
asuant.cdufojactual IN ('2807953001')
AND asuant.cdufojactual IN
('2800542001')
OR asuant.cdufojactual NOT IN ('2807953001')
AND asuant.cdufojrpt IN ('2807953001')
)
)
)
)
-- búsqueda de antecedentes
AND (
antecedente.diasvalidez < (SYSDATE - asuant.fcpresentacion)
AND (0 < (select count (*) from
ofre_configreparto config,
ofre_verclsreparto ver
where
antecedente.cdconfigreparto = ver.idconfigreparto
and asuant.idverclsrpt = ver.idverclsrpt
and config.IDCONFIGREPARTO = VER.IDCONFIGREPARTO
)
OR (
--Buscamos los intervinientes con el mismo tipo de intervención
EXISTS (
SELECT *
FROM ints_asunto_intvasu intv,
INTS_C_TIPOINTVPROJ ipro
WHERE
intv.fcbaja IS NULL
AND intv.cdtipointvproj = antecedente.cdtipointvproj
and ipro.cdtipointvproj = intv.cdtipointvproj
and
(antecedente.itrol = ipro.itrol and antecedente.cdtipointvproj is null
or
antecedente.itrol is null and antecedente.cdtipointvproj = intv.cdtipointvproj
or
antecedente.itrol = ipro.itrol and antecedente.cdtipointvproj = intv.cdtipointvproj
)
)
)-- fin OR de tipo de intervención
OR (
-- antecedentes por materia
asuant.cdfamidelimate = antecedente.cdfamidelimate
AND asuant.cdfuncion = antecedente.cdfuncionmateria
AND asuant.cdtipoasunto = antecedente.cdtipoasunto
AND asuant.cdtipodelimate = antecedente.cdtipodelimate
)
OR (-- por tipo de procedimiento
proj.cdtipoproj =
antecedente.cdtipoproj
and asuant.cdfuncion = CDFUNCIONPROCEDIMIENTO
and asuant.cdtipoasunto = CDTIPOASUNTOPROCEDIMIENTO
and proj.cdtipoproj = antecedente.CDTIPOPROJ)
)
)
-- condicion de número de límite de registros
AND antecedente.nmlimitereg <
(SELECT COUNT (*)
FROM ints_asunto
WHERE fcpresentacion > (SYSDATE - antecedente.diasvalidez))
SELECT asuant.idasunto,
aufoj.cdestadoregistro, -- 'ENV' o 'REP'
asuant.itasuntoenmovimiento, -- 'S' o 'N'
asuant.cdufojactual,
asuant.cdufojrpt,
asuant.cdtipoasunto, asuant.nmregistroofre, asuant.anyoregistroofre,
asuant.cdtipoprojoriext, asuant.numprojoriext, asuant.anyoprojoriext,
(select nvl(
(select 'S' from dual
where
((sysdate between asuant.FCINISECRETOACT and asuant.FCFINSECRETOACT)
or (asuant.FCINISECRETOACT < sysdate and asuant.FCFINSECRETOACT is null))),
'N')
from dual) itsecretosumario
, DECODE((select 'S' from dual where asuant.cdufojactual in ('2807953001')), 'S', 'S', 'N') as cdufojactualDestinoORR,
DECODE((select 'S' from dual where asuant.cdufojactual in ('2800542001')), 'S', 'S', 'N' ) as cdufojactualDestinoEAR,
DECODE((select 'S' from dual where asuant.cdufojrpt in ('2807953001')), 'S', 'S', 'N' ) as cdufojrptDestinoORR
, --coincidencia por interviniente
antecedente.cdintv,
antecedente.nombreintv,
antecedente.CDFUNCIONINTERVINIENTE,
antecedente.ITROL,
antecedente.CDTIPOASUNTO,
antecedente.CDTIPOINTVPROJ,
--coincidencia por materia
antecedente.CDFUNCIONMATERIA,
antecedente.CDTIPOASUNTOMATERIA,
antecedente.CDTIPODELIMATE,
antecedente.cdfamidelimate,
antecedente.dstipodelimate,
-- coincidencia tipo de procedimiento
antecedente.CDFUNCIONPROCEDIMIENTO,
antecedente.CDTIPOASUNTOPROCEDIMIENTO,
antecedente.CDTIPOPROJ,
antecedente.dstipoproj,
-- coincidencia clase de reparto
antecedente.cdconfigreparto,
asuant.idverclsrpt AS idverclsrpt,
antecedente.CDCLSRPT
FROM ( -- antecedentes por clase de reparto
SELECT
--coincidencia por interviniente
NULL AS cdintv,
null as nombreintv,
null as CDFUNCIONINTERVINIENTE,
null as ITROL,
null as CDTIPOASUNTO,
null as CDTIPOINTVPROJ,
null as DSTIPOINTVPROJ,
--coincidencia por materia
NULL AS CDFUNCIONMATERIA,
null as CDTIPOASUNTOMATERIA,
null as CDTIPODELIMATE,
null as cdfamidelimate,
null as dstipodelimate,
-- coincidencia tipo de procedimiento
NULL AS CDFUNCIONPROCEDIMIENTO,
null as CDTIPOASUNTOPROCEDIMIENTO,
null as CDTIPOPROJ,
null as dstipoproj,
-- coincidencia clase de reparto
null AS cdconfigreparto,
ver.idverclsrpt AS idverclsrpt,
cls.CDCLSRPT as CDCLSRPT,
-- resto de campos
ant.idcondrptanteced, ant.diasvalidez,
ant.nmlimitereg,
cond.idcondrpt idcondrpt,
ant.prioridad
FROM ofre_condrpt cond,
ofre_condrptanteced ant,
ofre_condrptanteced_clsreparto antcls,
ofre_verclsreparto ver,
ofre_c_clsreparto cls,
ofre_configreparto conf
WHERE cond.idcondrpt = ant.idcondrpt
AND cond.idcondrpt = '30225'
AND antcls.idcondrptanteced = ant.idcondrptanteced
AND ver.idconfigreparto = antcls.cdconfigreparto
and CONF.IDCONFIGREPARTO = antcls.cdconfigreparto
and CLS.IDCLSRPT = CONF.IDCLSRPT
and conf.fcbaja is null
and cls.fcbaja is null
and ver.fcbaja is null
and antcls.fcbaja is null
and cond.fcbaja is null
and ant.fcbaja is null
UNION ALL
-- antecedentes por interviniente
SELECT
--coincidencia por interviniente
INTV.CDINTVASUNTO AS cdintv,
null as nombreintv,
antintv.cdfuncion as CDFUNCIONINTERVINIENTE,
antintv.itrol as ITROL,
antintv.cdtipoasunto as CDTIPOASUNTOINTERVINIENTE,
antintv.CDTIPOINTVPROJ as CDTIPOINTVPROJ,
DSTIPOINTVPROJ as DSTIPOINTVPROJ,
--coincidencia por materia
NULL AS CDFUNCIONMATERIA,
null as CDTIPOASUNTOMATERIA,
null as CDTIPODELIMATE,
null as cdfamidelimate,
null as dstipodelimate,
-- coincidencia tipo de procedimiento
NULL AS CDFUNCIONPROCEDIMIENTO,
null as CDTIPOASUNTOPROCEDIMIENTO,
null as CDTIPOPROJ,
null as dstipoproj,
-- coincidencia clase de reparto
null AS cdconfigreparto,
null AS idverclsrpt,
null as CDCLSRPT,
-- resto de campos
ant.idcondrptanteced, ant.diasvalidez,
ant.nmlimitereg,
cond.idcondrpt idcondrpt,
ant.prioridad
FROM ofre_condrpt cond,
ofre_condrptanteced ant,
ofre_condrptanteced_intv antintv,
ints_asunto asu,
ints_asunto_intvasu intv,
ints_c_tipointvproj tipointvproj
WHERE
asu.idasunto = '1200151666' --el asunto a repartir
AND cond.idcondrpt = '30225'
and intv.idasunto = asu.idasunto
and intv.fcbaja is not null
and cond.idcondrpt = ant.idcondrpt
and intv.cdtipointvproj = tipointvproj.cdtipointvproj
and ( --tipo intv
ANTINTV.CDTIPOINTVPROJ = INTV.CDTIPOINTVPROJ
and antintv.itrol is null
or
-- por rol
tipointvproj.itrol = antintv.itrol
and ANTINTV.CDTIPOINTVPROJ is null
or
-- los dos
ANTINTV.CDTIPOINTVPROJ = INTV.CDTIPOINTVPROJ
and ANTINTV.CDTIPOINTVPROJ is null
)
AND antintv.idcondrptanteced = ant.idcondrptanteced
and ant.fcbaja is null
and antintv.fcbaja is null
and cond.fcbaja is null
UNION ALL
-- antecedentes por materia
SELECT
--coincidencia por interviniente
NULL AS cdintv,
null as nombreintv,
null as CDFUNCIONINTERVINIENTE,
null as ITROL,
null as CDTIPOASUNTOINTERVINIENTE,
null as CDTIPOINTVPROJ,
null as DSTIPOINTVPROJ,
--coincidencia por materia
antmat.cdfuncion AS CDFUNCIONMATERIA,
antmat.cdtipoasunto as CDTIPOASUNTOMATERIA,
antmat.cdtipodelimate as CDTIPODELIMATE,
antmat.cdfamidelimate as cdfamidelimate,
dstipodelimate as dstipodelimate,
-- coincidencia tipo de procedimiento
NULL AS CDFUNCIONPROCEDIMIENTO,
null as CDTIPOASUNTOPROCEDIMIENTO,
null as CDTIPOPROJ,
null as dstipoproj,
-- coincidencia clase de reparto
null AS cdconfigreparto,
null AS idverclsrpt,
null as CDCLSRPT,
-- resto de campos
ant.idcondrptanteced, ant.diasvalidez,
ant.nmlimitereg,
cond.idcondrpt idcondrpt,
ant.prioridad
FROM ofre_condrpt cond,
ofre_condrptanteced ant,
ofre_condrptanteced_materia antmat,
ints_c_tipodelimate mat
WHERE cond.idcondrpt = ant.idcondrpt
AND cond.idcondrpt = '30225'
AND antmat.idcondrptanteced = ant.idcondrptanteced
and mat.CDFAMIDELIMATE = antmat.cdfamidelimate
and mat.CDTIPODELIMATE = antmat.cdtipodelimate
and ant.fcbaja is null
and antmat.fcbaja is null
and cond.fcbaja is null
UNION ALL
-- antecedentes por tipo de procedimiento
SELECT
--coincidencia por interviniente
NULL AS cdintv,
null as nombreintv,
null as CDFUNCIONINTERVINIENTE,
null as ITROL,
null as CDTIPOASUNTOINTERVINIENTE,
null as CDTIPOINTVPROJ,
null as DSTIPOINTVPROJ,
--coincidencia por materia
NULL AS CDFUNCIONMATERIA,
null as CDTIPOASUNTOMATERIA,
null as CDTIPODELIMATE,
null as cdfamidelimate,
null as dstipodelimate,
-- coincidencia tipo de procedimiento
anttip.cdfuncion AS CDFUNCIONPROCEDIMIENTO,
anttip.cdtipoasunto as CDTIPOASUNTOPROCEDIMIENTO,
anttip.cdtipoproj as CDTIPOPROJ,
dstipoproj as dstipoproj,
-- coincidencia clase de reparto
null AS cdconfigreparto,
null AS idverclsrpt,
null as CDCLSRPT,
-- resto de campos
ant.idcondrptanteced, ant.diasvalidez,
ant.nmlimitereg,
cond.idcondrpt idcondrpt,
ant.prioridad
FROM ofre_condrpt cond,
ofre_condrptanteced ant,
ofre_condrptanteced_tipoproj anttip,
ints_c_tipoprorgjud tipoproj
WHERE cond.idcondrpt = ant.idcondrpt
AND cond.idcondrpt = '30225'
AND anttip.idcondrptanteced = ant.idcondrptanteced
and TIPOPROJ.CDTIPOPROJ = ANTTIP.CDTIPOPROJ
and cond.fcbaja is null
and anttip.fcbaja is null
and ant.fcbaja is null order by prioridad asc) antecedente,
ints_asunto asuant,
ints_asunto_ufoj aufoj,
ints_prorgjud proj
WHERE
-- casamientos ^^
asuant.fcbaja IS NULL
AND asuant.idverclsrpt IS NOT NULL
AND asuant.cdufojrpt IS NOT NULL
AND aufoj.cdufoj = asuant.cdufojactual
AND aufoj.idasunto = asuant.idasunto
AND aufoj.cdestadoregistro <> 'ANU'
AND asuant.cdprojori = proj.cdproj(+)
-- condiciones funcionales 09/2009
AND ( aufoj.cdestadoregistro = 'REP' -- repartido y no enviado
OR ( aufoj.cdestadoregistro = 'ENV' -- enviado
AND (
asuant.itasuntoenmovimiento = 'N'
--aceptado en destino
AND ( asuant.cdufojactual IN ('2807953001')
OR ( asuant.cdufojactual IN
('2800542001')
AND asuant.cdufojrpt IN ('2807953001')
)
)
OR ( -- no aceptado en destino, itasuntoenmovimiento='S'
asuant.cdufojactual IN ('2807953001')
AND asuant.cdufojactual IN
('2800542001')
OR asuant.cdufojactual NOT IN ('2807953001')
AND asuant.cdufojrpt IN ('2807953001')
)
)
)
)
-- búsqueda de antecedentes
AND (
antecedente.diasvalidez < (SYSDATE - asuant.fcpresentacion)
AND (0 < (select count (*) from
ofre_configreparto config,
ofre_verclsreparto ver
where
antecedente.cdconfigreparto = ver.idconfigreparto
and asuant.idverclsrpt = ver.idverclsrpt
and config.IDCONFIGREPARTO = VER.IDCONFIGREPARTO
)
OR (
--Buscamos los intervinientes con el mismo tipo de intervención
EXISTS (
SELECT *
FROM ints_asunto_intvasu intv,
INTS_C_TIPOINTVPROJ ipro
WHERE
intv.fcbaja IS NULL
AND intv.cdtipointvproj = antecedente.cdtipointvproj
and ipro.cdtipointvproj = intv.cdtipointvproj
and
(antecedente.itrol = ipro.itrol and antecedente.cdtipointvproj is null
or
antecedente.itrol is null and antecedente.cdtipointvproj = intv.cdtipointvproj
or
antecedente.itrol = ipro.itrol and antecedente.cdtipointvproj = intv.cdtipointvproj
)
)
)-- fin OR de tipo de intervención
OR (
-- antecedentes por materia
asuant.cdfamidelimate = antecedente.cdfamidelimate
AND asuant.cdfuncion = antecedente.cdfuncionmateria
AND asuant.cdtipoasunto = antecedente.cdtipoasunto
AND asuant.cdtipodelimate = antecedente.cdtipodelimate
)
OR (-- por tipo de procedimiento
proj.cdtipoproj =
antecedente.cdtipoproj
and asuant.cdfuncion = CDFUNCIONPROCEDIMIENTO
and asuant.cdtipoasunto = CDTIPOASUNTOPROCEDIMIENTO
and proj.cdtipoproj = antecedente.CDTIPOPROJ)
)
)
-- condicion de número de límite de registros
AND antecedente.nmlimitereg <
(SELECT COUNT (*)
FROM ints_asunto
WHERE fcpresentacion > (SYSDATE - antecedente.diasvalidez))
Suscribirse a:
Entradas (Atom)