
* Test na viacnasobny vyskyt operacie "PR" na jednom stredisku a karte


USE (m.fn_obraty) ALIAS obraty IN 0

SELECT DISTINCT c_karty,c_stredisk, COUNT(c_dokl) AS pocet FROM obraty GROUP BY c_karty,c_stredisk WHERE operace="PR" INTO CURSOR viacpr readwrite
dele for pocet <= 2
PACK 
SCAN 
    SCATTER MEMVAR 
	SELECT MIN(c_dokl) AS c_dokl FROM obraty WHERE c_stredisk = m.c_stredisk .AND. c_karty=m.c_karty .AND. operace="PR" INTO CURSOR viacpr_c_dokl
	IF RECCOUNT()>0
		m.c_dokl = viacpr_c_dokl.c_dokl
        DELETE FROM obraty WHERE c_stredisk = m.viacpr_c_stredisk AND c_karty = m.viacpr_c_karty AND operace = "PR" AND c_dokl<>m.viacpr_c_dokl
	ENDIF 
ENDSCAN 
