<?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="EaiSvcNameMonthly">
	
	<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 EAISVCNAME,
					  SUM(S1MNTRSMTNOITM)  AS MNTRSMTNOITM1,  SUM(S1MNERRNOITM)  AS MNERRNOITM1,
			          SUM(S2MNTRSMTNOITM)  AS MNTRSMTNOITM2,  SUM(S2MNERRNOITM)  AS MNERRNOITM2,
			          SUM(S3MNTRSMTNOITM)  AS MNTRSMTNOITM3,  SUM(S3MNERRNOITM)  AS MNERRNOITM3,
			          SUM(S4MNTRSMTNOITM)  AS MNTRSMTNOITM4,  SUM(S4MNERRNOITM)  AS MNERRNOITM4,
			          SUM(S5MNTRSMTNOITM)  AS MNTRSMTNOITM5,  SUM(S5MNERRNOITM)  AS MNERRNOITM5,
			          SUM(S6MNTRSMTNOITM)  AS MNTRSMTNOITM6,  SUM(S6MNERRNOITM)  AS MNERRNOITM6,
			          SUM(S7MNTRSMTNOITM)  AS MNTRSMTNOITM7,  SUM(S7MNERRNOITM)  AS MNERRNOITM7,
			          SUM(S8MNTRSMTNOITM)  AS MNTRSMTNOITM8,  SUM(S8MNERRNOITM)  AS MNERRNOITM8,
			          SUM(S9MNTRSMTNOITM)  AS MNTRSMTNOITM9,  SUM(S9MNERRNOITM)  AS MNERRNOITM9,
			          SUM(S10MNTRSMTNOITM) AS MNTRSMTNOITM10, SUM(S10MNERRNOITM) AS MNERRNOITM10,
			          SUM(S11MNTRSMTNOITM) AS MNTRSMTNOITM11, SUM(S11MNERRNOITM) AS MNERRNOITM11,
			          SUM(S12MNTRSMTNOITM) AS MNTRSMTNOITM12, SUM(S12MNERRNOITM) AS MNERRNOITM12
				  FROM $schemaId$.TSEAIST04
				 WHERE TRIM(STATCYM) BETWEEN #searchStart# AND #searchEnd#
				 GROUP BY EAISVCNAME
				 ORDER BY EAISVCNAME
			  ) A
		 LEFT OUTER JOIN $schemaId$.TSEAIHE01 B
		   ON  TRIM(A.EAISVCNAME) = B.EAISVCNAME
		<dynamic prepend="WHERE">
			<isNotEmpty prepend="AND" property="searchEaiBzwkDstcd">
					( TRIM(A.EAISVCNAME) LIKE UPPER('%' || TRIM(#searchEaiBzwkDstcd#) || '%') OR
	        		  TRIM(B.EAISVCDESC) LIKE UPPER('%'||TRIM(#searchEaiBzwkDstcd#)||'%') )
			</isNotEmpty>
		</dynamic>
	</statement>
   
	<statement id="selectByEaiSvcNameMonthly" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT ST04.EAISVCNAME AS "EAISVCNAME",
	           COALESCE(HE01.EAISVCDESC, 'UNKNOWN') AS "EAISVCDESC",
			   ST04.MNTRSMTNOITM1  AS "MNTRSMTNOITM1",  ST04.MNERRNOITM1  AS "MNERRNOITM1",
			   ST04.MNTRSMTNOITM2  AS "MNTRSMTNOITM2",  ST04.MNERRNOITM2  AS "MNERRNOITM2",
			   ST04.MNTRSMTNOITM3  AS "MNTRSMTNOITM3",  ST04.MNERRNOITM3  AS "MNERRNOITM3",
			   ST04.MNTRSMTNOITM4  AS "MNTRSMTNOITM4",  ST04.MNERRNOITM4  AS "MNERRNOITM4",
			   ST04.MNTRSMTNOITM5  AS "MNTRSMTNOITM5",  ST04.MNERRNOITM5  AS "MNERRNOITM5",
			   ST04.MNTRSMTNOITM6  AS "MNTRSMTNOITM6",  ST04.MNERRNOITM6  AS "MNERRNOITM6",
			   ST04.MNTRSMTNOITM7  AS "MNTRSMTNOITM7",  ST04.MNERRNOITM7  AS "MNERRNOITM7",
			   ST04.MNTRSMTNOITM8  AS "MNTRSMTNOITM8",  ST04.MNERRNOITM8  AS "MNERRNOITM8",
			   ST04.MNTRSMTNOITM9  AS "MNTRSMTNOITM9",  ST04.MNERRNOITM9  AS "MNERRNOITM9",
			   ST04.MNTRSMTNOITM10 AS "MNTRSMTNOITM10", ST04.MNERRNOITM10 AS "MNERRNOITM10",
			   ST04.MNTRSMTNOITM11 AS "MNTRSMTNOITM11", ST04.MNERRNOITM11 AS "MNERRNOITM11",
			   ST04.MNTRSMTNOITM12 AS "MNTRSMTNOITM12", ST04.MNERRNOITM12 AS "MNERRNOITM12" 
		  FROM ( SELECT EAISVCNAME,
					    SUM(S1MNTRSMTNOITM)  AS MNTRSMTNOITM1,  SUM(S1MNERRNOITM)  AS MNERRNOITM1,
			            SUM(S2MNTRSMTNOITM)  AS MNTRSMTNOITM2,  SUM(S2MNERRNOITM)  AS MNERRNOITM2,
			            SUM(S3MNTRSMTNOITM)  AS MNTRSMTNOITM3,  SUM(S3MNERRNOITM)  AS MNERRNOITM3,
			            SUM(S4MNTRSMTNOITM)  AS MNTRSMTNOITM4,  SUM(S4MNERRNOITM)  AS MNERRNOITM4,
			            SUM(S5MNTRSMTNOITM)  AS MNTRSMTNOITM5,  SUM(S5MNERRNOITM)  AS MNERRNOITM5,
			            SUM(S6MNTRSMTNOITM)  AS MNTRSMTNOITM6,  SUM(S6MNERRNOITM)  AS MNERRNOITM6,
			            SUM(S7MNTRSMTNOITM)  AS MNTRSMTNOITM7,  SUM(S7MNERRNOITM)  AS MNERRNOITM7,
			            SUM(S8MNTRSMTNOITM)  AS MNTRSMTNOITM8,  SUM(S8MNERRNOITM)  AS MNERRNOITM8,
			            SUM(S9MNTRSMTNOITM)  AS MNTRSMTNOITM9,  SUM(S9MNERRNOITM)  AS MNERRNOITM9,
			            SUM(S10MNTRSMTNOITM) AS MNTRSMTNOITM10, SUM(S10MNERRNOITM) AS MNERRNOITM10,
			            SUM(S11MNTRSMTNOITM) AS MNTRSMTNOITM11, SUM(S11MNERRNOITM) AS MNERRNOITM11,
			            SUM(S12MNTRSMTNOITM) AS MNTRSMTNOITM12, SUM(S12MNERRNOITM) AS MNERRNOITM12
				   FROM $schemaId$.TSEAIST04
				  WHERE TRIM(STATCYM) BETWEEN #searchStart# AND #searchEnd#
				  GROUP BY EAISVCNAME
				) ST04
		   LEFT OUTER JOIN $schemaId$.TSEAIHE01 HE01
			 ON  TRIM(ST04.EAISVCNAME) = HE01.EAISVCNAME
			<dynamic prepend="WHERE">
				<isNotEmpty prepend="AND" property="searchEaiBzwkDstcd">
					( TRIM(ST04.EAISVCNAME) LIKE UPPER('%' || TRIM(#searchEaiBzwkDstcd#) || '%') OR
	        		  TRIM(HE01.EAISVCDESC) LIKE UPPER('%'||TRIM(#searchEaiBzwkDstcd#)||'%') )
				</isNotEmpty>
			</dynamic>
		 ORDER BY HE01.EAISVCNAME
	</statement>
</sqlMap>
