Hello ... Prompt, something I can not understand, distinct in the cursor does not work or what? have a cursor with a distinct, which I get around in a loop .. If the request from the cursor to perform separately, then returns 1 record, if distinct clean, there will be 2 entries. A loop through the cursor with distinct runs 2 times.
DECLARE cur CURSOR FOR
SELECT DISTINCT t.DATPR, A.ACCOUNT_NO
FROM postgkh.tt_krd t
INNER JOIN postgkh.account A ON t.LS = A.ACCOUNT_NO
INNER JOIN postgkh.resid RID USING(ACCOUNT_ID)
INNER JOIN postgkh.reseller R USING(RESELLER_ID)
WHERE r.RESELLER_ID = RID
ORDER BY A.ACCOUNT_ID;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
OPEN cur;
REPEAT
FETCH cur INTO PR_DATE,ACCID, ACCNO;
SET LIM_FP = postgkh.GET_ACCOUNT_FP(ACCID) - INTERVAL 1 DAY;
IF(LIM_FP>PR_DATE) THEN
IF(TMP IS NULL OR TMP<>ACCNO) THEN
SET TMP = ACCNO;
SET ERR = CONCAT(ERR,', ',ACCNO);
END IF;
END IF;
UNTIL done END REPEAT;
CLOSE cur;