<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="BapMessageMonthly">
  
  <statement id="selectListCount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        SELECT COUNT(*) AS "TOTALCOUNT"
        	 , SUM(MNTRSMTNOITM1)	AS "MNTRSMTNOITM1_SUM"
             , SUM(MNERRNOITM1)		AS "MNERRNOITM1_SUM"
			 , SUM(MNTRSMTNOITM2)	AS "MNTRSMTNOITM2_SUM"
             , SUM(MNERRNOITM2)		AS "MNERRNOITM2_SUM"
			 , SUM(MNTRSMTNOITM3)	AS "MNTRSMTNOITM3_SUM"
             , SUM(MNERRNOITM3)		AS "MNERRNOITM3_SUM"
			 , SUM(MNTRSMTNOITM4)	AS "MNTRSMTNOITM4_SUM"
             , SUM(MNERRNOITM4)		AS "MNERRNOITM4_SUM"
			 , SUM(MNTRSMTNOITM5)	AS "MNTRSMTNOITM5_SUM"
             , SUM(MNERRNOITM5)		AS "MNERRNOITM5_SUM"
			 , SUM(MNTRSMTNOITM6)	AS "MNTRSMTNOITM6_SUM"
             , SUM(MNERRNOITM6)		AS "MNERRNOITM6_SUM"
			 , SUM(MNTRSMTNOITM7)	AS "MNTRSMTNOITM7_SUM"
             , SUM(MNERRNOITM7)		AS "MNERRNOITM7_SUM"
			 , SUM(MNTRSMTNOITM8)	AS "MNTRSMTNOITM8_SUM"
             , SUM(MNERRNOITM8)		AS "MNERRNOITM8_SUM"
			 , SUM(MNTRSMTNOITM9)	AS "MNTRSMTNOITM9_SUM"
             , SUM(MNERRNOITM9)		AS "MNERRNOITM9_SUM"
			 , SUM(MNTRSMTNOITM10)	AS "MNTRSMTNOITM10_SUM"
             , SUM(MNERRNOITM10)	AS "MNERRNOITM10_SUM"
			 , SUM(MNTRSMTNOITM11)	AS "MNTRSMTNOITM11_SUM"
             , SUM(MNERRNOITM11)	AS "MNERRNOITM11_SUM"
			 , SUM(MNTRSMTNOITM12)	AS "MNTRSMTNOITM12_SUM"
             , SUM(MNERRNOITM12)	AS "MNERRNOITM12_SUM"        
          FROM (
				SELECT
			        NVL(SUM(CASE WHEN MM = '01' THEN ProcCount END), 0)    AS "MNTRSMTNOITM1" 
			      , NVL(SUM(CASE WHEN MM = '01' THEN ErrCount END), 0)     AS "MNERRNOITM1"   
			      , NVL(SUM(CASE WHEN MM = '02' THEN ProcCount END), 0)    AS "MNTRSMTNOITM2" 
			      , NVL(SUM(CASE WHEN MM = '02' THEN ErrCount END), 0)     AS "MNERRNOITM2"   
			      , NVL(SUM(CASE WHEN MM = '03' THEN ProcCount END), 0)    AS "MNTRSMTNOITM3" 
			      , NVL(SUM(CASE WHEN MM = '03' THEN ErrCount END), 0)     AS "MNERRNOITM3"   
			      , NVL(SUM(CASE WHEN MM = '04' THEN ProcCount END), 0)    AS "MNTRSMTNOITM4" 
			      , NVL(SUM(CASE WHEN MM = '04' THEN ErrCount END), 0)     AS "MNERRNOITM4"   
			      , NVL(SUM(CASE WHEN MM = '05' THEN ProcCount END), 0)    AS "MNTRSMTNOITM5" 
			      , NVL(SUM(CASE WHEN MM = '05' THEN ErrCount END), 0)     AS "MNERRNOITM5"   
			      , NVL(SUM(CASE WHEN MM = '06' THEN ProcCount END), 0)    AS "MNTRSMTNOITM6" 
			      , NVL(SUM(CASE WHEN MM = '06' THEN ErrCount END), 0)     AS "MNERRNOITM6"   
			      , NVL(SUM(CASE WHEN MM = '07' THEN ProcCount END), 0)    AS "MNTRSMTNOITM7" 
			      , NVL(SUM(CASE WHEN MM = '07' THEN ErrCount END), 0)     AS "MNERRNOITM7"   
			      , NVL(SUM(CASE WHEN MM = '08' THEN ProcCount END), 0)    AS "MNTRSMTNOITM8" 
			      , NVL(SUM(CASE WHEN MM = '08' THEN ErrCount END), 0)     AS "MNERRNOITM8"   
			      , NVL(SUM(CASE WHEN MM = '09' THEN ProcCount END), 0)    AS "MNTRSMTNOITM9" 
			      , NVL(SUM(CASE WHEN MM = '09' THEN ErrCount END), 0)     AS "MNERRNOITM9"   
			      , NVL(SUM(CASE WHEN MM = '10' THEN ProcCount END), 0)    AS "MNTRSMTNOITM10"
			      , NVL(SUM(CASE WHEN MM = '10' THEN ErrCount END), 0)     AS "MNERRNOITM10"  
			      , NVL(SUM(CASE WHEN MM = '11' THEN ProcCount END), 0)    AS "MNTRSMTNOITM11"
			      , NVL(SUM(CASE WHEN MM = '11' THEN ErrCount END), 0)     AS "MNERRNOITM11"  
			      , NVL(SUM(CASE WHEN MM = '12' THEN ProcCount END), 0)    AS "MNTRSMTNOITM12"
			      , NVL(SUM(CASE WHEN MM = '12' THEN ErrCount END), 0)     AS "MNERRNOITM12"  
				FROM
			        (
				SELECT
		                SUBSTR(ES01.SNDSTARTDATE, 1, 4) AS STATCY
		              , SUBSTR(ES01.SNDSTARTDATE, 5, 2) AS MM
		              , ES01.INTFID
		              , EA04.INTFNAME
		              , EA04.WORKGRPCD
		              , SUM(CASE WHEN ES01.ERRYN = 'C' THEN 1 ELSE 0 END) AS ProcCount
		              , SUM(CASE WHEN ES01.ERRYN = 'C' THEN 0 ELSE 1 END) AS ErrCount
		        FROM  $schemaId$.TSEAIES01 ES01, $schemaId$.TSEAIEA04 EA04
		        WHERE ES01.SNDSTARTDATE &gt;= #searchStart# || '0000000000'
		        AND   ES01.SNDSTARTDATE &lt;= #searchEnd# || '9999999999'
		        AND   EA04.INTFID = ES01.INTFID
				<isNotEmpty prepend="AND" property="searchIntfId">
					(  TRIM(EA04.INTFID) LIKE CONCAT( '%',CONCAT( UPPER(#searchIntfId#) , '%') ) OR
						  EA04.INTFNAME LIKE CONCAT( '%',CONCAT( UPPER(#searchIntfId#) , '%') )   )
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchEaiBzwkDstcd">
					(  EA04.WORKGRPCD = UPPER(#searchEaiBzwkDstcd#)  )
				</isNotEmpty>					        
		        GROUP BY
		                SUBSTR(ES01.SNDSTARTDATE, 1, 4)
		              , SUBSTR(ES01.SNDSTARTDATE, 5, 2)
		              , ES01.INTFID
		              , EA04.INTFNAME
		              , EA04.WORKGRPCD
		        ) TMP1
		GROUP BY STATCY, INTFID, INTFNAME, WORKGRPCD
			)
  </statement>
  
  <statement id="selectByIntfIdMonthly" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT
           STATCY      AS "STATCY"
           , INTFID      AS "INTFID"
           , INTFNAME   AS "INTFNAME"
           , WORKGRPCD   AS "WORKGRPCD"
            , (SELECT BZWKDSTICDESC FROM $schemaId$.TSEAICM01 WHERE EAIBZWKDSTCD =  TMP1.WORKGRPCD) "BJOBBZWKNAME"
		      , NVL(SUM(CASE WHEN MM = '01' THEN ProcCount END), 0)    AS "MNTRSMTNOITM1" 
		      , NVL(SUM(CASE WHEN MM = '01' THEN ErrCount END), 0)     AS "MNERRNOITM1"   
		      , NVL(SUM(CASE WHEN MM = '02' THEN ProcCount END), 0)    AS "MNTRSMTNOITM2" 
		      , NVL(SUM(CASE WHEN MM = '02' THEN ErrCount END), 0)     AS "MNERRNOITM2"   
		      , NVL(SUM(CASE WHEN MM = '03' THEN ProcCount END), 0)    AS "MNTRSMTNOITM3" 
		      , NVL(SUM(CASE WHEN MM = '03' THEN ErrCount END), 0)     AS "MNERRNOITM3"   
		      , NVL(SUM(CASE WHEN MM = '04' THEN ProcCount END), 0)    AS "MNTRSMTNOITM4" 
		      , NVL(SUM(CASE WHEN MM = '04' THEN ErrCount END), 0)     AS "MNERRNOITM4"   
		      , NVL(SUM(CASE WHEN MM = '05' THEN ProcCount END), 0)    AS "MNTRSMTNOITM5" 
		      , NVL(SUM(CASE WHEN MM = '05' THEN ErrCount END), 0)     AS "MNERRNOITM5"   
		      , NVL(SUM(CASE WHEN MM = '06' THEN ProcCount END), 0)    AS "MNTRSMTNOITM6" 
		      , NVL(SUM(CASE WHEN MM = '06' THEN ErrCount END), 0)     AS "MNERRNOITM6"   
		      , NVL(SUM(CASE WHEN MM = '07' THEN ProcCount END), 0)    AS "MNTRSMTNOITM7" 
		      , NVL(SUM(CASE WHEN MM = '07' THEN ErrCount END), 0)     AS "MNERRNOITM7"   
		      , NVL(SUM(CASE WHEN MM = '08' THEN ProcCount END), 0)    AS "MNTRSMTNOITM8" 
		      , NVL(SUM(CASE WHEN MM = '08' THEN ErrCount END), 0)     AS "MNERRNOITM8"   
		      , NVL(SUM(CASE WHEN MM = '09' THEN ProcCount END), 0)    AS "MNTRSMTNOITM9" 
		      , NVL(SUM(CASE WHEN MM = '09' THEN ErrCount END), 0)     AS "MNERRNOITM9"   
		      , NVL(SUM(CASE WHEN MM = '10' THEN ProcCount END), 0)    AS "MNTRSMTNOITM10"
		      , NVL(SUM(CASE WHEN MM = '10' THEN ErrCount END), 0)     AS "MNERRNOITM10"  
		      , NVL(SUM(CASE WHEN MM = '11' THEN ProcCount END), 0)    AS "MNTRSMTNOITM11"
		      , NVL(SUM(CASE WHEN MM = '11' THEN ErrCount END), 0)     AS "MNERRNOITM11"  
		      , NVL(SUM(CASE WHEN MM = '12' THEN ProcCount END), 0)    AS "MNTRSMTNOITM12"
		      , NVL(SUM(CASE WHEN MM = '12' THEN ErrCount END), 0)     AS "MNERRNOITM12"  
			FROM
		        (
			SELECT
	                SUBSTR(ES01.SNDSTARTDATE, 1, 4) AS STATCY
	              , SUBSTR(ES01.SNDSTARTDATE, 5, 2) AS MM
	              , ES01.INTFID
	              , EA04.INTFNAME
	              , EA04.WORKGRPCD
	              , SUM(CASE WHEN ES01.ERRYN = 'C' THEN 1 ELSE 0 END) AS ProcCount
	              , SUM(CASE WHEN ES01.ERRYN = 'C' THEN 0 ELSE 1 END) AS ErrCount
	        FROM  $schemaId$.TSEAIES01 ES01, $schemaId$.TSEAIEA04 EA04
	        WHERE ES01.SNDSTARTDATE &gt;= #searchStart# || '0000000000'
	        AND   ES01.SNDSTARTDATE &lt;= #searchEnd# || '9999999999'
	        AND   EA04.INTFID = ES01.INTFID
			<isNotEmpty prepend="AND" property="searchIntfId">
				(  TRIM(EA04.INTFID) LIKE CONCAT( '%',CONCAT( UPPER(#searchIntfId#) , '%') ) OR
					  EA04.INTFNAME LIKE CONCAT( '%',CONCAT( UPPER(#searchIntfId#) , '%') )   )
			</isNotEmpty>	
			<isNotEmpty prepend="AND" property="searchEaiBzwkDstcd">
					(  EA04.WORKGRPCD = UPPER(#searchEaiBzwkDstcd#)  )
			</isNotEmpty>				        
	        GROUP BY
	                SUBSTR(ES01.SNDSTARTDATE, 1, 4)
	              , SUBSTR(ES01.SNDSTARTDATE, 5, 2)
	              , ES01.INTFID
	              , EA04.INTFNAME
	              , EA04.WORKGRPCD
	        ) TMP1
		GROUP BY STATCY, INTFID, INTFNAME, WORKGRPCD
  </statement>
</sqlMap>
