728x90
<insert id="setInsertGiveCoupon">
/* contractDAO.setInsertGiveCoupon */
INSERT INTO th_cpn_hist
(
give_no
, cpn_id
, cust_id
, use_yn
, frst_reg_dt
, frst_rgtr_id
, delete_yn
) SELECT
(SELECT COALESCE(MAX(give_no::int4),0)+1 FROM th_cpn_hist)
, #{give_cpn_id}
, #{cust_id}
, 'N'
, now()
, #{s_user_id}
, 'N'
WHERE NOT EXISTS (
select * from th_cpn_hist where cpn_id = #{give_cpn_id} and cust_id = #{cust_id}
)
</insert>
UPDATE tn_coupon SET
cpn_nm = 'test1'
, cpn_memo = '테스트22221'
, cpn_ty_cd = '2'
, last_mod_dt = now()
WHERE cpn_id = '1' and not EXISTS (
SELECT 1
FROM th_cpn_hist
WHERE cpn_id = '1' and use_yn = 'Y'
);
728x90