BEGIN
DECLARE curCouponId int;
DECLARE curPutOutUserType int;
DECLARE record_not_found int;
DECLARE cur_coupon CURSOR for select z.* from (select DISTINCT(c.couponId),c.putOutUserType from tab_template_coupon c,tab_template_coupon_sendinfo s where c.couponId = s.couponId and c.PutOutType=2) z;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET record_not_found = 1;
open cur_coupon;
allcoupon:LOOP
fetch cur_coupon into curCouponId,curPutOutUserType;
IF record_not_found THEN
LEAVE allcoupon;
END IF;
update tab_template_coupon_sendinfo set putOutUserType = curPutOutUserType where couponId = curCouponId;
END LOOP allcoupon;
close cur_coupon;
END