Web Analytics

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))