daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT
  2. REG.NOMBRE AS REGIONAL_NOMBRE,
  3. ORG.NUMERO AS SEDE_NUMERO,
  4. ORG.DESCRIPCION AS SEDE_DESCRIPCION,
  5. SUM(CASE WHEN CU.NOMBRE = '51080404002' THEN (IA.MONTO_DEBE - IA.MONTO_HABER) ELSE 0 END) AS B_ODONT,
  6. SUM(CASE WHEN (CU.NOMBRE = '51080404010' OR CU.NOMBRE = '51080404018') THEN (IA.MONTO_DEBE - IA.MONTO_HABER) ELSE 0 END) AS B_REINT_CONS_PRAC,
  7. COALESCE(MAX(B_USO.B_USO_BIOA),0) AS B_USO_BIOA,
  8. COALESCE(MAX(B_USO.B_USO_BIOB),0) AS B_USO_BIOB,
  9. COALESCE(MAX(B_USO.B_USO_BIOAC),0) AS B_USO_BIOAC,
  10. SUM(CASE WHEN ((CU.NOMBRE >= '51080102001' AND CU.NOMBRE <= '51080102999') OR (CU.NOMBRE >= '51080103001' AND CU.NOMBRE <= '51080103999') OR (CU.NOMBRE >= '51080201001' AND CU.NOMBRE <= '51080299999' AND CU.NOMBRE NOT IN ('51080207003','51080209006','51080209007','51080209010'))) THEN (IA.MONTO_DEBE - IA.MONTO_HABER) ELSE 0 END) AS MEDICOS,
  11. SUM(CASE WHEN (CU.NOMBRE >= '51070201001' AND CU.NOMBRE <= '51070201999') THEN (IA.MONTO_DEBE - IA.MONTO_HABER) ELSE 0 END) AS SUBSIDIOS,
  12. SUM(CASE WHEN ((CU.NOMBRE >= '51080409001' AND CU.NOMBRE <= '51080409999') OR CU.NOMBRE = '51080401003') THEN (IA.MONTO_DEBE - IA.MONTO_HABER) ELSE 0 END) AS REINTEGROS
  13. FROM ITEM_ASIENTO IA
  14. INNER JOIN CUENTA CU ON CU.ID = IA.CUENTA_ID
  15. INNER JOIN ASIENTO ASI ON ASI.ID = IA.ASIENTO_ID
  16. INNER JOIN PERIODO PER ON PER.ID = ASI.PERIODO_ID
  17. INNER JOIN EJERCICIO EJ ON EJ.ID = PER.EJERCICIO_ID
  18. INNER JOIN TIPO_DATO_CONTABLE TP ON TP.ID = PER.TIPO_PERIODO_ID
  19. INNER JOIN ORGANIZACION ORG ON ORG.CONTRAPARTE_ID = ASI.ORGANIZACION_ID
  20. INNER JOIN REGIONAL REG ON ORG.REGIONAL_ID = REG.ID
  21. LEFT JOIN
  22. (
  23.    SELECT
  24.    SUM(CASE WHEN TB.NOMBRE = 'BIOA' THEN 1 ELSE 0 END) AS B_USO_BIOA,
  25.    SUM(CASE WHEN TB.NOMBRE = 'BIOB' THEN 1 ELSE 0 END) AS B_USO_BIOB,
  26.    SUM(CASE WHEN TB.NOMBRE = 'BIOAC' THEN 1 ELSE 0 END) AS B_USO_BIOAC,
  27.    TRB.ORGANIZACION_ID AS ORGANIZACION_ID
  28.    FROM TRANSACCION_BONO TRB
  29.    INNER JOIN TIPO_TRANSACCION_BONO TTRB ON TTRB.ID = TRB.TIPO_TRANSACCION_BONO_ID
  30.    INNER JOIN TIPO_BONO TB ON TB.ID = TRB.TIPO_BONO_ID
  31.    WHERE TB.NOMBRE IN ('BIOA','BIOB','BIOAC')
  32.    AND TTRB.NOMBRE = 'USO'
  33.    GROUP BY TRB.ORGANIZACION_ID
  34. )
  35. AS B_USO ON B_USO.ORGANIZACION_ID = ORG.CONTRAPARTE_ID
  36. WHERE EJ.CERRADO IS TRUE
  37. AND EJ.ID = 2
  38. AND TP.DISCRIMINATOR = 'T_PER'
  39. AND TP.NOMBRE = 'NML'
  40. GROUP BY REG.NOMBRE,ORG.NUMERO,ORG.DESCRIPCION;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top