>I'm not sure why do you've to do that but wouldn't it be the same as
SELECT NoClient,MAX(OrderMain) AS SortOrder FROM Temp ;
>WHERE OrderMain>0 ;
>GROUP BY NoClient ORDER BY SortOrder INTO CURSOR Temp2
Yes, that is better. Thanks
If you don't mind, I am sending you a cursor by email with 3 lines to execute to simulate the production problem I was facing. If you can find something better, let me know.