<?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="UseDateControl">
	<statement id="selectListCount" resultClass="java.lang.Integer">
		SELECT count(1) "TOTALCOUNT"
		FROM $schemaId$.TSEAIHE01 he01  
	      LEFT OUTER JOIN (SELECT NAME, STARTDATE, ENDDATE, USEYN FROM $schemaId$.tseaifr10 WHERE TYPE='01') fr10 
	        ON he01.EAISVCNAME = fr10.name 
	    <dynamic prepend="WHERE">
			<isNotEmpty prepend="AND" property="searchName"> 
				UPPER(EAISVCNAME) LIKE CONCAT('%', #searchName#, '%')
			</isNotEmpty>
		</dynamic> 		
	</statement>
		
 	<statement id="selectList" resultClass="java.util.HashMap"> 
 		SELECT * 
 		FROM ( 
 				SELECT @NO := @NO + 1 AS ROWNO , 
 				       he01.EAISVCNAME NAME, he01.EAISVCDESC "DESC", COALESCE(fr10.STARTDATE,'') STARTDATE, COALESCE(fr10.ENDDATE,'') ENDDATE, COALESCE(fr10.USEYN,0) USEYN
				FROM $schemaId$.TSEAIHE01 he01  
			      LEFT OUTER JOIN (SELECT NAME, STARTDATE, ENDDATE, USEYN FROM $schemaId$.tseaifr10 WHERE TYPE='01') fr10 
			        ON he01.EAISVCNAME = fr10.name 
			    WHERE (@NO := 0) = 0
	 			<isNotEmpty prepend="AND" property="searchName"> 
	 				UPPER(EAISVCNAME) LIKE CONCAT('%', #searchName#, '%')
	 			</isNotEmpty>
 			) ORGTABLE 
		WHERE ROWNO BETWEEN #startNum# AND #endNum# 
 	</statement>	 
	
	<statement id="selectDetail" resultClass="java.util.HashMap">
		SELECT he01.EAISVCNAME NAME, he01.EAISVCDESC "DESC", COALESCE(fr10.STARTDATE,'') STARTDATE, COALESCE(fr10.ENDDATE,'99991231') ENDDATE, COALESCE(fr10.USEYN,0) USEYN
		FROM $schemaId$.TSEAIHE01 he01  
	      LEFT OUTER JOIN (SELECT NAME, STARTDATE, ENDDATE, USEYN FROM $schemaId$.tseaifr10 WHERE TYPE='01') fr10 
	        ON he01.EAISVCNAME = fr10.name 
		WHERE EAISVCNAME =#name# 	
	</statement>  
	
 	<statement id="merge"  parameterClass="java.util.HashMap">
 		INSERT INTO $schemaId$.tseaifr10 (TYPE, NAME, STARTDATE, ENDDATE, USEYN) VALUES ('01',#name#, #startDate#, #endDate#, #useYn#)
 		ON DUPLICATE KEY
 		UPDATE STARTDATE=#startDate#, ENDDATE=#endDate#, USEYN=#useYn#
 	</statement>
 
</sqlMap>
